Files
FrozenFriendsYume/packages/backend/built/server/api/endpoints/gallery/posts/update.js
T
2026-07-26 18:25:37 +09:00

81 lines
1.9 KiB
JavaScript

import define from "../../../define.js";
import { DriveFiles, GalleryPosts } from "../../../../../models/index.js";
import { HOUR } from "../../../../../const.js";
export const meta = {
tags: [
"gallery"
],
requireCredential: true,
kind: "write:gallery",
limit: {
duration: HOUR,
max: 300
},
res: {
type: "object",
optional: false,
nullable: false,
ref: "GalleryPost"
},
errors: {}
};
export const paramDef = {
type: "object",
properties: {
postId: {
type: "string",
format: "misskey:id"
},
title: {
type: "string",
minLength: 1
},
description: {
type: "string",
nullable: true
},
fileIds: {
type: "array",
uniqueItems: true,
minItems: 1,
maxItems: 32,
items: {
type: "string",
format: "misskey:id"
}
},
isSensitive: {
type: "boolean",
default: false
}
},
required: [
"postId",
"title",
"fileIds"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const files = (await Promise.all(ps.fileIds.map((fileId)=>DriveFiles.findOneBy({
id: fileId,
userId: user.id
})))).filter((file)=>file != null);
if (files.length === 0) {
throw new Error();
}
await GalleryPosts.update({
id: ps.postId,
userId: user.id
}, {
updatedAt: new Date(),
title: ps.title,
description: ps.description,
isSensitive: ps.isSensitive,
fileIds: files.map((file)=>file.id)
});
const post = await GalleryPosts.findOneByOrFail({
id: ps.postId
});
return await GalleryPosts.pack(post, user);
});