summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/flash/update.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/server/api/endpoints/flash/update.ts')
-rw-r--r--packages/backend/src/server/api/endpoints/flash/update.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/endpoints/flash/update.ts b/packages/backend/src/server/api/endpoints/flash/update.ts
new file mode 100644
index 0000000000..9ab17a61e8
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/flash/update.ts
@@ -0,0 +1,78 @@
+import ms from 'ms';
+import { Not } from 'typeorm';
+import { Inject, Injectable } from '@nestjs/common';
+import type { FlashsRepository, DriveFilesRepository } from '@/models/index.js';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import { DI } from '@/di-symbols.js';
+import { ApiError } from '../../error.js';
+
+export const meta = {
+ tags: ['flash'],
+
+ requireCredential: true,
+
+ kind: 'write:flash',
+
+ limit: {
+ duration: ms('1hour'),
+ max: 300,
+ },
+
+ errors: {
+ noSuchFlash: {
+ message: 'No such flash.',
+ code: 'NO_SUCH_FLASH',
+ id: '611e13d2-309e-419a-a5e4-e0422da39b02',
+ },
+
+ accessDenied: {
+ message: 'Access denied.',
+ code: 'ACCESS_DENIED',
+ id: '08e60c88-5948-478e-a132-02ec701d67b2',
+ },
+ },
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {
+ flashId: { type: 'string', format: 'misskey:id' },
+ title: { type: 'string' },
+ summary: { type: 'string' },
+ script: { type: 'string' },
+ permissions: { type: 'array', items: {
+ type: 'string',
+ } },
+ },
+ required: ['flashId', 'title', 'summary', 'script', 'permissions'],
+} as const;
+
+// eslint-disable-next-line import/no-default-export
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> {
+ constructor(
+ @Inject(DI.flashsRepository)
+ private flashsRepository: FlashsRepository,
+
+ @Inject(DI.driveFilesRepository)
+ private driveFilesRepository: DriveFilesRepository,
+ ) {
+ super(meta, paramDef, async (ps, me) => {
+ const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
+ if (flash == null) {
+ throw new ApiError(meta.errors.noSuchFlash);
+ }
+ if (flash.userId !== me.id) {
+ throw new ApiError(meta.errors.accessDenied);
+ }
+
+ await this.flashsRepository.update(flash.id, {
+ updatedAt: new Date(),
+ title: ps.title,
+ summary: ps.summary,
+ script: ps.script,
+ permissions: ps.permissions,
+ });
+ });
+ }
+}