mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add /attachments/removeUnused DocApi endpoint to hard delete all unused attachments in document
Summary: Adds methods to delete metadata rows based on timeDeleted. The flag expiredOnly determines if it only deletes attachments that were soft-deleted 7 days ago, or just all soft-deleted rows. Then any actual file data that doesn't have matching metadata is deleted. Test Plan: DocApi test Reviewers: paulfitz Reviewed By: paulfitz Subscribers: dsagal Differential Revision: https://phab.getgrist.com/D3364
This commit is contained in:
@@ -56,6 +56,7 @@ import {ServerColumnGetters} from 'app/server/lib/ServerColumnGetters';
|
||||
import {localeFromRequest} from "app/server/lib/ServerLocale";
|
||||
import {allowedEventTypes, isUrlAllowed, WebhookAction, WebHookSecret} from "app/server/lib/Triggers";
|
||||
import {handleOptionalUpload, handleUpload} from "app/server/lib/uploads";
|
||||
import * as assert from 'assert';
|
||||
import * as contentDisposition from 'content-disposition';
|
||||
import {Application, NextFunction, Request, RequestHandler, Response} from "express";
|
||||
import * as _ from "lodash";
|
||||
@@ -235,6 +236,18 @@ export class DocWorkerApi {
|
||||
await activeDoc.updateUsedAttachments();
|
||||
res.json(null);
|
||||
}));
|
||||
this._app.post('/api/docs/:docId/attachments/removeUnused', isOwner, withDoc(async (activeDoc, req, res) => {
|
||||
const expiredOnly = isAffirmative(req.query.expiredonly);
|
||||
const verifyFiles = isAffirmative(req.query.verifyfiles);
|
||||
await activeDoc.removeUnusedAttachments(expiredOnly);
|
||||
if (verifyFiles) {
|
||||
assert.deepStrictEqual(
|
||||
await activeDoc.docStorage.all(`SELECT DISTINCT fileIdent AS ident FROM _grist_Attachments ORDER BY ident`),
|
||||
await activeDoc.docStorage.all(`SELECT ident FROM _gristsys_Files ORDER BY ident`),
|
||||
);
|
||||
}
|
||||
res.json(null);
|
||||
}));
|
||||
|
||||
// Adds records given in a column oriented format,
|
||||
// returns an array of row IDs
|
||||
|
||||
Reference in New Issue
Block a user