Skip to content

Commit

Permalink
Add support for activity/revisions/logs retention (directus#24058)
Browse files Browse the repository at this point in the history
* Add retention support for `directus_activity` and `directus_revisions` (directus#23410)

* add retention support

* add changeset

* add docs

* rework imports

* skip processing for no records

* improve retention tests

* improve tests

* add error handling

* remove redundant while condition in retention

* improve error message

* increase retention to 90 days

* add lock

* Use the action constant

* Skip the full table count

* Add false to disable in docs

* Reduce batch to 500 for db compat

* Add timeout to lock

* skip revisions if activities is more frequent

* Update docs/self-hosted/config-options.md

Co-authored-by: Kevin Lewis <kvn@lws.io>

* Update docs/self-hosted/config-options.md

Co-authored-by: Kevin Lewis <kvn@lws.io>

* RETENTION_TASKS are no longer constant

* fix formatting for retentions enabled config option

* reword RETENTION_SCHEDULE config option

* add explicit return types and update to async for consistency

* fix schedules tests to be async

* update jsdoc to correctly indicate schedule job

* add correct default value for retention schedules

---------

Co-authored-by: ian <licitdev@gmail.com>
Co-authored-by: Kevin Lewis <kvn@lws.io>

* Removed outdated logic for versioning (directus#23749)

* Extract comments to a separate table (directus#22295)

* Add directus_comments migration

* Add comments controller and service

* Remove from activity

* Update system-data and types

* Refactor app with new endpoints

* Expose service

* Update app minimal permissions

* Add collection translation

* Define relations

* Allow comment creation only if there's item read access

* Patch for MSSQL double constraints issue

* Fix users service test

* Add sdk support

* Update specs

* Fix formatting

* Fix specs error

* Patch whoopsie

* Remove obsolete GraphQL mutations

* Update required fields

* Remove unused vars

* Allow edit and delete of legacy activity comments

* Remove legacy comments from SDK

* Add changeset

* Batch upwards migration

* Update SDK to use keysOrQuery

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>

* Update implementation for keysOrQuery

* Remove singleton check

* Update SDK to use keysOrQuery 2

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>

* Update keysOrQuery typedoc

* Fix import

* Update migration timestamp

* fixed import

* Update api/src/utils/get-service.ts

* utilize chunk processing in migration

* formatting

* only services extended from itemservice should be added

* remove redundant checks from comment header

* update comment service to v11 permission format

* specify missing required fields

* Mock comments in users test

* Simplify migration and update date

* WIP legacy access

* Optimise imports

* WIP app cleanup

* Update loadUserPreviews typing

Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Read legacy comments

* Parse using comments service

* Perform migration directly

* Fix legacy app sort query which uses id

* Migrate legacy comments in mutations

* Reduce api semver

* Update app recommended permissions

* Recommend updating of comment only

* replace hardcoded type with existing one

* Allow users to update or delete their own comments

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Skip further access validation for non-existent collections

* Check if collection exists before the admin check

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Fix incorrect legacy check

Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Fix merging of count when db returns count as string type

* Remove unused import

---------

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Consolidate content versioning (directus#22413)

* Add migration

* Use the new delta field

* Add cast-json flag

* Fix typing

* Fetch existing deltas if version created during migration

* Add changeset

* Add version delta field into sdk schema

* Update migration timestamp

* Update versions.save() to return finalVersionDelta

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>

* Sort on DB level

* Update migration date

* Disallow passing delta via create/update

* Update docs & specs

* Fix save response

* Remove unnecessary access check

Already checked by the subsequent itemsService.readOne call

* Update changeset

* Don't require update perms on versions for save

* Optimize validateCreateData

* update to new validateAccess

* Update docs/reference/system/versions.md

* Remove migration of delta

* Rename to legacy

* Add missed changes for Remove migration of delta in 2e2f50f

* Update docs/reference/system/versions.md

---------

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Update migration dates

* api change should be major for versioning

* Remove comment paths from activity reference

* Added comments reference

* Added directus_comments to table of system collections

* The linter demands newline

* Revert function renaming for patch semver

* Use transaction in down migration for comments (directus#23715)

* Remove outdated logic for versioning

* Fix migration

* Update api/src/database/migrations/20240924B-populate-versioning-deltas.ts

* add changeset

* reword changeset

---------

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>
Co-authored-by: Kevin Lewis <kvn@lws.io>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>

* Removed outdated logic for comments (directus#23748)

* Extract comments to a separate table (directus#22295)

* Add directus_comments migration

* Add comments controller and service

* Remove from activity

* Update system-data and types

* Refactor app with new endpoints

* Expose service

* Update app minimal permissions

* Add collection translation

* Define relations

* Allow comment creation only if there's item read access

* Patch for MSSQL double constraints issue

* Fix users service test

* Add sdk support

* Update specs

* Fix formatting

* Fix specs error

* Patch whoopsie

* Remove obsolete GraphQL mutations

* Update required fields

* Remove unused vars

* Allow edit and delete of legacy activity comments

* Remove legacy comments from SDK

* Add changeset

* Batch upwards migration

* Update SDK to use keysOrQuery

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>

* Update implementation for keysOrQuery

* Remove singleton check

* Update SDK to use keysOrQuery 2

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>

* Update keysOrQuery typedoc

* Fix import

* Update migration timestamp

* fixed import

* Update api/src/utils/get-service.ts

* utilize chunk processing in migration

* formatting

* only services extended from itemservice should be added

* remove redundant checks from comment header

* update comment service to v11 permission format

* specify missing required fields

* Mock comments in users test

* Simplify migration and update date

* WIP legacy access

* Optimise imports

* WIP app cleanup

* Update loadUserPreviews typing

Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Read legacy comments

* Parse using comments service

* Perform migration directly

* Fix legacy app sort query which uses id

* Migrate legacy comments in mutations

* Reduce api semver

* Update app recommended permissions

* Recommend updating of comment only

* replace hardcoded type with existing one

* Allow users to update or delete their own comments

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Skip further access validation for non-existent collections

* Check if collection exists before the admin check

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Fix incorrect legacy check

Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Fix merging of count when db returns count as string type

* Remove unused import

---------

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Consolidate content versioning (directus#22413)

* Add migration

* Use the new delta field

* Add cast-json flag

* Fix typing

* Fetch existing deltas if version created during migration

* Add changeset

* Add version delta field into sdk schema

* Update migration timestamp

* Update versions.save() to return finalVersionDelta

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>

* Sort on DB level

* Update migration date

* Disallow passing delta via create/update

* Update docs & specs

* Fix save response

* Remove unnecessary access check

Already checked by the subsequent itemsService.readOne call

* Update changeset

* Don't require update perms on versions for save

* Optimize validateCreateData

* update to new validateAccess

* Update docs/reference/system/versions.md

* Remove migration of delta

* Rename to legacy

* Add missed changes for Remove migration of delta in 2e2f50f

* Update docs/reference/system/versions.md

---------

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Update migration dates

* api change should be major for versioning

* Remove comment paths from activity reference

* Added comments reference

* Added directus_comments to table of system collections

* The linter demands newline

* Revert function renaming for patch semver

* Use transaction in down migration for comments (directus#23715)

* Remove outdated logic for comments

* remove duplicate app access permission

* remove unused import/params in gql

* remove remaining comment code in activity

* remove remaining activity logic in comment

* add changeset

* reword changeset

---------

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>
Co-authored-by: Kevin Lewis <kvn@lws.io>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>

* Update config-options.md

* add missing docs changeset for retentions

* ensure selected id is not ambiguous for joins

* Restrict comment create, update and delete to authenticated users (directus#23996)

* Extract comments to a separate table (directus#22295)

* Add directus_comments migration

* Add comments controller and service

* Remove from activity

* Update system-data and types

* Refactor app with new endpoints

* Expose service

* Update app minimal permissions

* Add collection translation

* Define relations

* Allow comment creation only if there's item read access

* Patch for MSSQL double constraints issue

* Fix users service test

* Add sdk support

* Update specs

* Fix formatting

* Fix specs error

* Patch whoopsie

* Remove obsolete GraphQL mutations

* Update required fields

* Remove unused vars

* Allow edit and delete of legacy activity comments

* Remove legacy comments from SDK

* Add changeset

* Batch upwards migration

* Update SDK to use keysOrQuery

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>

* Update implementation for keysOrQuery

* Remove singleton check

* Update SDK to use keysOrQuery 2

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>

* Update keysOrQuery typedoc

* Fix import

* Update migration timestamp

* fixed import

* Update api/src/utils/get-service.ts

* utilize chunk processing in migration

* formatting

* only services extended from itemservice should be added

* remove redundant checks from comment header

* update comment service to v11 permission format

* specify missing required fields

* Mock comments in users test

* Simplify migration and update date

* WIP legacy access

* Optimise imports

* WIP app cleanup

* Update loadUserPreviews typing

Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Read legacy comments

* Parse using comments service

* Perform migration directly

* Fix legacy app sort query which uses id

* Migrate legacy comments in mutations

* Reduce api semver

* Update app recommended permissions

* Recommend updating of comment only

* replace hardcoded type with existing one

* Allow users to update or delete their own comments

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Skip further access validation for non-existent collections

* Check if collection exists before the admin check

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Fix incorrect legacy check

Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Fix merging of count when db returns count as string type

* Remove unused import

---------

Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>

* Consolidate content versioning (directus#22413)

* Add migration

* Use the new delta field

* Add cast-json flag

* Fix typing

* Fetch existing deltas if version created during migration

* Add changeset

* Add version delta field into sdk schema

* Update migration timestamp

* Update versions.save() to return finalVersionDelta

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>

* Sort on DB level

* Update migration date

* Disallow passing delta via create/update

* Update docs & specs

* Fix save response

* Remove unnecessary access check

Already checked by the subsequent itemsService.readOne call

* Update changeset

* Don't require update perms on versions for save

* Optimize validateCreateData

* update to new validateAccess

* Update docs/reference/system/versions.md

* Remove migration of delta

* Rename to legacy

* Add missed changes for Remove migration of delta in 2e2f50f

* Update docs/reference/system/versions.md

---------

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>

* Update migration dates

* api change should be major for versioning

* Remove comment paths from activity reference

* Added comments reference

* Added directus_comments to table of system collections

* The linter demands newline

* Revert function renaming for patch semver

* Use transaction in down migration for comments (directus#23715)

* Remove outdated logic for comments

* remove duplicate app access permission

* remove unused import/params in gql

* remove remaining comment code in activity

* remove remaining activity logic in comment

* add changeset

* reword changeset

* restrict comment CUD to authenticated users

* update docs

* add changeset

* skip mention processing if none are present

* update restriction wording in the docs

---------

Co-authored-by: ian <licitdev@gmail.com>
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>
Co-authored-by: Kevin Lewis <kvn@lws.io>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>

* remove foreign key constraint on comment `collection` column

* update migration comment wording

* Update api/src/database/migrations/20240924A-migrate-legacy-comments.ts

Co-authored-by: ian <licitdev@gmail.com>

---------

Co-authored-by: ian <licitdev@gmail.com>
Co-authored-by: Kevin Lewis <kvn@lws.io>
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
  • Loading branch information
8 people authored Dec 2, 2024
1 parent 92684fc commit ce4bfe0
Show file tree
Hide file tree
Showing 29 changed files with 461 additions and 658 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-rules-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@directus/api': patch
---

Removed outdated logic for the versioning service
7 changes: 7 additions & 0 deletions .changeset/perfect-pens-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@directus/env': minor
'@directus/api': minor
'docs': patch
---

Added retention support for `directus_activity` and `directus_revisions`
7 changes: 7 additions & 0 deletions .changeset/silver-comics-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@directus/system-data': patch
'@directus/api': patch
'@directus/sdk': patch
---

Removed outdated logic for the comment service
6 changes: 6 additions & 0 deletions .changeset/thick-timers-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'docs': patch
'@directus/api': patch
---

Restricted comment create, update and delete to authenticated users
11 changes: 7 additions & 4 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ import serverRouter from './controllers/server.js';
import settingsRouter from './controllers/settings.js';
import sharesRouter from './controllers/shares.js';
import translationsRouter from './controllers/translations.js';
import { default as tusRouter, scheduleTusCleanup } from './controllers/tus.js';
import tusRouter from './controllers/tus.js';
import usersRouter from './controllers/users.js';
import utilsRouter from './controllers/utils.js';
import versionsRouter from './controllers/versions.js';
import webhooksRouter from './controllers/webhooks.js';
import retentionSchedule from './schedules/retention.js';
import telemetrySchedule from './schedules/telemetry.js';
import tusSchedule from './schedules/tus.js';
import {
isInstalled,
validateDatabaseConnection,
Expand All @@ -64,7 +67,6 @@ import rateLimiterGlobal from './middleware/rate-limiter-global.js';
import rateLimiter from './middleware/rate-limiter-ip.js';
import sanitizeQuery from './middleware/sanitize-query.js';
import schema from './middleware/schema.js';
import { initTelemetry } from './telemetry/index.js';
import { getConfigFromEnv } from './utils/get-config-from-env.js';
import { Url } from './utils/url.js';
import { validateStorage } from './utils/validate-storage.js';
Expand Down Expand Up @@ -321,8 +323,9 @@ export default async function createApp(): Promise<express.Application> {

await emitter.emitInit('routes.after', { app });

initTelemetry();
scheduleTusCleanup();
await retentionSchedule();
await telemetrySchedule();
await tusSchedule();

await emitter.emitInit('app.after', { app });

Expand Down
129 changes: 2 additions & 127 deletions api/src/controllers/activity.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { ErrorCode, InvalidPayloadError, isDirectusError } from '@directus/errors';
import express from 'express';
import Joi from 'joi';
import { respond } from '../middleware/respond.js';
import useCollection from '../middleware/use-collection.js';
import { validateBatch } from '../middleware/validate-batch.js';
import { ActivityService } from '../services/activity.js';
import { CommentsService } from '../services/comments.js';
import { MetaService } from '../services/meta.js';
import asyncHandler from '../utils/async-handler.js';

Expand All @@ -25,40 +22,16 @@ const readHandler = asyncHandler(async (req, res, next) => {
});

let result;
let isComment;

if (req.singleton) {
result = await service.readSingleton(req.sanitizedQuery);
} else if (req.body.keys) {
result = await service.readMany(req.body.keys, req.sanitizedQuery);
} else {
const sanitizedFilter = req.sanitizedQuery.filter;

if (
sanitizedFilter &&
'_and' in sanitizedFilter &&
Array.isArray(sanitizedFilter['_and']) &&
sanitizedFilter['_and'].find(
(andItem) => 'action' in andItem && '_eq' in andItem['action'] && andItem['action']['_eq'] === 'comment',
)
) {
const commentsService = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'activity',
});

result = await commentsService.readByQuery(req.sanitizedQuery);
isComment = true;
} else {
result = await service.readByQuery(req.sanitizedQuery);
}
result = await service.readByQuery(req.sanitizedQuery);
}

const meta = await metaService.getMetaForQuery(
isComment ? 'directus_comments' : 'directus_activity',
req.sanitizedQuery,
);
const meta = await metaService.getMetaForQuery('directus_activity', req.sanitizedQuery);

res.locals['payload'] = {
data: result,
Expand Down Expand Up @@ -90,102 +63,4 @@ router.get(
respond,
);

const createCommentSchema = Joi.object({
comment: Joi.string().required(),
collection: Joi.string().required(),
item: [Joi.number().required(), Joi.string().required()],
});

router.post(
'/comment',
asyncHandler(async (req, res, next) => {
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'activity',
});

const { error } = createCommentSchema.validate(req.body);

if (error) {
throw new InvalidPayloadError({ reason: error.message });
}

const primaryKey = await service.createOne(req.body);

try {
const record = await service.readOne(primaryKey, req.sanitizedQuery);

res.locals['payload'] = {
data: record || null,
};
} catch (error: any) {
if (isDirectusError(error, ErrorCode.Forbidden)) {
return next();
}

throw error;
}

return next();
}),
respond,
);

const updateCommentSchema = Joi.object({
comment: Joi.string().required(),
});

router.patch(
'/comment/:pk',
asyncHandler(async (req, res, next) => {
const commentsService = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'activity',
});

const { error } = updateCommentSchema.validate(req.body);

if (error) {
throw new InvalidPayloadError({ reason: error.message });
}

const primaryKey = await commentsService.updateOne(req.params['pk']!, req.body);

try {
const record = await commentsService.readOne(primaryKey, req.sanitizedQuery);

res.locals['payload'] = {
data: record || null,
};
} catch (error: any) {
if (isDirectusError(error, ErrorCode.Forbidden)) {
return next();
}

throw error;
}

return next();
}),
respond,
);

router.delete(
'/comment/:pk',
asyncHandler(async (req, _res, next) => {
const commentsService = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'activity',
});

await commentsService.deleteOne(req.params['pk']!);

return next();
}),
respond,
);

export default router;
7 changes: 0 additions & 7 deletions api/src/controllers/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ router.post(
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'comments',
});

const savedKeys: PrimaryKey[] = [];
Expand Down Expand Up @@ -57,7 +56,6 @@ const readHandler = asyncHandler(async (req, res, next) => {
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'comments',
});

const metaService = new MetaService({
Expand Down Expand Up @@ -88,7 +86,6 @@ router.get(
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'comments',
});

const record = await service.readOne(req.params['pk']!, req.sanitizedQuery);
Expand All @@ -106,7 +103,6 @@ router.patch(
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'comments',
});

let keys: PrimaryKey[] = [];
Expand Down Expand Up @@ -142,7 +138,6 @@ router.patch(
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'comments',
});

const primaryKey = await service.updateOne(req.params['pk']!, req.body);
Expand Down Expand Up @@ -170,7 +165,6 @@ router.delete(
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'comments',
});

if (Array.isArray(req.body)) {
Expand All @@ -193,7 +187,6 @@ router.delete(
const service = new CommentsService({
accountability: req.accountability,
schema: req.schema,
serviceOrigin: 'comments',
});

await service.deleteOne(req.params['pk']!);
Expand Down
19 changes: 0 additions & 19 deletions api/src/controllers/tus.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { PermissionsAction } from '@directus/types';
import { Router } from 'express';
import { RESUMABLE_UPLOADS } from '../constants.js';
import getDatabase from '../database/index.js';
import { validateAccess } from '../permissions/modules/validate-access/validate-access.js';
import { createTusServer } from '../services/tus/index.js';
import asyncHandler from '../utils/async-handler.js';
import { getSchema } from '../utils/get-schema.js';
import { scheduleSynchronizedJob, validateCron } from '../utils/schedule.js';

const mapAction = (method: string): PermissionsAction => {
switch (method) {
Expand Down Expand Up @@ -52,22 +49,6 @@ const handler = asyncHandler(async (req, res) => {
cleanupServer();
});

export function scheduleTusCleanup() {
if (!RESUMABLE_UPLOADS.ENABLED) return;

if (validateCron(RESUMABLE_UPLOADS.SCHEDULE)) {
scheduleSynchronizedJob('tus-cleanup', RESUMABLE_UPLOADS.SCHEDULE, async () => {
const [tusServer, cleanupServer] = await createTusServer({
schema: await getSchema(),
});

await tusServer.cleanUpExpiredUploads();

cleanupServer();
});
}
}

const router = Router();

router.post('/', checkFileAccess, handler);
Expand Down
10 changes: 1 addition & 9 deletions api/src/controllers/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,7 @@ router.get(

const { outdated, mainHash } = await service.verifyHash(version['collection'], version['item'], version['hash']);

let current;

if (version['delta']) {
current = version['delta'];
} else {
const saves = await service.getVersionSavesById(version['id']);

current = assign({}, ...saves);
}
const current = assign({}, version['delta']);

const main = await service.getMainItem(version['collection'], version['item']);

Expand Down
7 changes: 1 addition & 6 deletions api/src/database/migrations/20240909A-separate-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ export async function up(knex: Knex): Promise<void> {
await knex.schema.createTable('directus_comments', (table) => {
table.uuid('id').primary().notNullable();

table
.string('collection', 64)
.notNullable()
.references('collection')
.inTable('directus_collections')
.onDelete('CASCADE');
table.string('collection', 64).notNullable();

table.string('item').notNullable();
table.text('comment').notNullable();
Expand Down
Loading

0 comments on commit ce4bfe0

Please sign in to comment.