Last active
September 5, 2025 08:56
-
-
Save danielberndt/3899cdbcb48b49dd069acef87115cb65 to your computer and use it in GitHub Desktop.
Codecks: Batch remove files via browser console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void (async () => { | |
| const subdomain = window.location.host.split(".")[0] | |
| 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"} } | |
| ) | |
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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] | |
| 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"} } | |
| ) | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment