Skip to content

Instantly share code, notes, and snippets.

@danielberndt
Last active September 5, 2025 08:56
Show Gist options
  • Select an option

  • Save danielberndt/3899cdbcb48b49dd069acef87115cb65 to your computer and use it in GitHub Desktop.

Select an option

Save danielberndt/3899cdbcb48b49dd069acef87115cb65 to your computer and use it in GitHub Desktop.

Revisions

  1. danielberndt revised this gist Sep 5, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion browser-console-files.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    // delete non-attachment files (filtered by date and file size)
    // delete any file no matter if used as attachment or not (filtered by date and file size)

    void (async () => {
    const subdomain = window.location.host.split(".")[0]
  2. danielberndt revised this gist Sep 5, 2025. 2 changed files with 44 additions and 0 deletions.
    File renamed without changes.
    44 changes: 44 additions & 0 deletions browser-console-files.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    // delete non-attachment files (filtered by date and file size)

    void (async () => {
    const subdomain = window.location.host.split(".")[0]
    const fileQuery = {
    createdAt: { op: "lt", value: "2024-09-04" },
    isDeleted: false,
    selfHosted: true,
    size: {op: "gt", value: 1000000},
    $order: "createdAt",
    $limit: 100
    };

    // build up the nested query and define which models and fields we want to receive
    const query = {
    _root: [
    {
    account: [
    {
    [`files(${JSON.stringify(fileQuery)})`]: [
    "id"
    ],
    },
    ],
    },
    ],
    };

    // pass the query to the api
    const data = await fetch(
    `https://api.codecks.io?query=${JSON.stringify(
    query
    )}&x-account=${subdomain}`,
    { credentials: "include" }
    ).then((r) => r.json());

    // parse the response and create delete request
    const files = Object.values(data.file)
    const body = {ids: files.map(f => f.id)}
    await fetch(
    `https://api.codecks.io/dispatch/attachments/batchDeleteByFileId?&x-account=${subdomain}`,
    { credentials: "include", method: "POST", body: JSON.stringify(body), headers: {"Content-Type": "application/json"} }
    )
    })()
  3. danielberndt revised this gist Sep 4, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion browser-console.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    void (async () => {
    const subdomain = "MYSUBDOMAIN"; // for e.g. MYSUBDOMAIN.codecks.io
    const subdomain = window.location.host.split(".")[0]
    const attachmentQuery = {
    createdAt: { op: "lt", value: "2024-09-04" },
    file: {
  4. danielberndt revised this gist Sep 4, 2025. No changes.
  5. danielberndt created this gist Sep 4, 2025.
    42 changes: 42 additions & 0 deletions browser-console.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    void (async () => {
    const subdomain = "MYSUBDOMAIN"; // for e.g. MYSUBDOMAIN.codecks.io
    const attachmentQuery = {
    createdAt: { op: "lt", value: "2024-09-04" },
    file: {
    isDeleted: false,
    selfHosted: true,
    },
    $order: "createdAt",
    $limit: 100
    };

    // build up the nested query and define which models and fields we want to receive
    const query = {
    _root: [
    {
    account: [
    {
    [`attachments(${JSON.stringify(attachmentQuery)})`]: [
    { file: ["id"] },
    ],
    },
    ],
    },
    ],
    };

    // pass the query to the api
    const data = await fetch(
    `https://api.codecks.io?query=${JSON.stringify(
    query
    )}&x-account=${subdomain}`,
    { credentials: "include" }
    ).then((r) => r.json());
    const attachments = Object.values(data.attachment)
    const body = {ids: attachments.map(a => a.id), fileIds: attachments.map(a => a.file)}
    await fetch(
    `https://api.codecks.io/dispatch/attachments/batchDeleteFile?&x-account=${subdomain}`,
    { credentials: "include", method: "POST", body: JSON.stringify(body), headers: {"Content-Type": "application/json"} }
    )

    })()