Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyatea committed Jan 31, 2025
1 parent 020c4f1 commit f2b93eb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ export class DriveService {
if (info.sensitive && profile!.autoSensitive) file.isSensitive = true;
if (info.sensitive && instance.setSensitiveFlagAutomatically) file.isSensitive = true;
if (userRoleNSFW) file.isSensitive = true;
if (file.isSensitiveByModerator) file.isSensitive = true;

if (url !== null) {
file.src = url;
Expand Down Expand Up @@ -660,6 +661,7 @@ export class DriveService {
@bindThis
public async updateFile(file: MiDriveFile, values: Partial<MiDriveFile>, updater: MiUser) {
const alwaysMarkNsfw = (await this.roleService.getUserPolicies(file.userId)).alwaysMarkNsfw;
const isModerator = await this.roleService.isModerator(updater);

if (values.name != null && !this.driveFileEntityService.validateFileName(values.name)) {
throw new DriveService.InvalidFileNameError();
Expand All @@ -680,6 +682,10 @@ export class DriveService {
}
}

if (isModerator && file.userId !== updater.id) {
values.isSensitiveByModerator = values.isSensitive;
}

await this.driveFilesRepository.update(file.id, values);

const fileObj = await this.driveFileEntityService.pack(file.id, updater, { self: true });
Expand All @@ -689,7 +695,7 @@ export class DriveService {
this.globalEventService.publishDriveStream(file.userId, 'fileUpdated', fileObj);
}

if (await this.roleService.isModerator(updater) && (file.userId !== updater.id)) {
if (isModerator && (file.userId !== updater.id)) {
if (values.isSensitive !== undefined && values.isSensitive !== file.isSensitive) {
const user = file.userId ? await this.usersRepository.findOneByOrFail({ id: file.userId }) : null;
if (values.isSensitive) {
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/core/entities/DriveFileEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export class DriveFileEntityService {
thumbnailUrl: this.getThumbnailUrl(file),
comment: file.comment,
folderId: file.folderId,
isSensitiveByModerator: opts.detail ? file.isSensitiveByModerator : null,
folder: opts.detail && file.folderId ? this.driveFolderEntityService.pack(file.folderId, {
detail: true,
}) : null,
Expand Down Expand Up @@ -247,6 +248,7 @@ export class DriveFileEntityService {
md5: file.md5,
size: file.size,
isSensitive: file.isSensitive,
isSensitiveByModerator: opts.detail ? file.isSensitiveByModerator : null,
blurhash: file.blurhash,
properties: opts.self ? file.properties : this.getPublicProperties(file),
url: opts.self ? file.url : this.getPublicUrl(file),
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/models/DriveFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ export class MiDriveFile {
})
public isSensitive: boolean;

@Index()
@Column('boolean', {
default: false,
})
public isSensitiveByModerator: boolean;

@Index()
@Column('boolean', {
default: false,
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/drive-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const packedDriveFileSchema = {
type: 'boolean',
optional: false, nullable: false,
},
isSensitiveByModerator: {
type: 'boolean',
optional: false, nullable: true,
},
blurhash: {
type: 'string',
optional: false, nullable: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const entities = [
...charts,
];

const log = process.env.NODE_ENV !== 'production';
const log = false;
const timeoutFinalizationRegistry = new FinalizationRegistry((reference: { name: string; timeout: NodeJS.Timeout }) => {
dbLogger.info(`Finalizing timeout: ${reference.name}`);
clearInterval(reference.timeout);
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/server/api/endpoints/drive/files/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export const meta = {
code: 'RESTRICTED_BY_ROLE',
id: '7f59dccb-f465-75ab-5cf4-3ce44e3282f7',
},

restrictedByModerator: {
message: 'The isSensitive specified by the moderator cannot be deleted.',
code: 'RESTRICTED_BY_MODERATOR',
id: '20e6c501-e579-400d-97e4-1c7efc286f35',
},
},
res: {
type: 'object',
Expand Down Expand Up @@ -90,6 +96,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.accessDenied);
}

if (!await this.roleService.isModerator(me) && !ps.isSensitive && file.isSensitiveByModerator) {
throw new ApiError(meta.errors.restrictedByModerator);
}

let packedFile;

try {
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/pages/drive.file.info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<div class="_gaps">
<MkInfo>{{ i18n.ts._fileViewer.thisPageCanBeSeenFromTheAuthor }}</MkInfo>
<MkInfo v-if="file && file.isSensitiveByModerator" :warn="true">{{ i18n.ts._fileViewer. }}</MkInfo>

Check failure on line 9 in packages/frontend/src/pages/drive.file.info.vue

View workflow job for this annotation

GitHub Actions / lint (frontend)

Parsing error: Unexpected end of expression
<MkLoading v-if="fetching"/>
<div v-else-if="file" class="_gaps">
<div :class="$style.filePreviewRoot">
Expand Down

0 comments on commit f2b93eb

Please sign in to comment.