// 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"} } ) })()