Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import define from "../../define.js";
|
||||
import { ClipNotes, Clips } from "../../../../models/index.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { genId } from "../../../../misc/gen-id.js";
|
||||
import { getNote } from "../../common/getters.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"account",
|
||||
"notes",
|
||||
"clips"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account",
|
||||
errors: {
|
||||
noSuchClip: {
|
||||
message: "No such clip.",
|
||||
code: "NO_SUCH_CLIP",
|
||||
id: "d6e76cc0-a1b5-4c7c-a287-73fa9c716dcf"
|
||||
},
|
||||
noSuchNote: {
|
||||
message: "No such note.",
|
||||
code: "NO_SUCH_NOTE",
|
||||
id: "fc8c0b49-c7a3-4664-a0a6-b418d386bb8b"
|
||||
},
|
||||
alreadyClipped: {
|
||||
message: "The note has already been clipped.",
|
||||
code: "ALREADY_CLIPPED",
|
||||
id: "734806c4-542c-463a-9311-15c512803965"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
clipId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
noteId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"clipId",
|
||||
"noteId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
userId: user.id
|
||||
});
|
||||
if (clip == null) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
const note = await getNote(ps.noteId, user).catch((err)=>{
|
||||
if (err.id === "9725d0ce-ba28-4dde-95a7-2cbb2c15de24") throw new ApiError(meta.errors.noSuchNote);
|
||||
throw err;
|
||||
});
|
||||
const exist = await ClipNotes.exist({
|
||||
where: {
|
||||
noteId: note.id,
|
||||
clipId: clip.id
|
||||
}
|
||||
});
|
||||
if (exist) {
|
||||
throw new ApiError(meta.errors.alreadyClipped);
|
||||
}
|
||||
await ClipNotes.insert({
|
||||
id: genId(),
|
||||
noteId: note.id,
|
||||
clipId: clip.id
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import define from "../../define.js";
|
||||
import { genId } from "../../../../misc/gen-id.js";
|
||||
import { Clips } from "../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"clips"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account",
|
||||
res: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "Clip"
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: {
|
||||
type: "string",
|
||||
minLength: 1,
|
||||
maxLength: 100
|
||||
},
|
||||
isPublic: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
},
|
||||
description: {
|
||||
type: "string",
|
||||
nullable: true,
|
||||
minLength: 1,
|
||||
maxLength: 2048
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"name"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const clip = await Clips.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user.id,
|
||||
name: ps.name,
|
||||
isPublic: ps.isPublic,
|
||||
description: ps.description
|
||||
}).then((x)=>Clips.findOneByOrFail(x.identifiers[0]));
|
||||
return await Clips.pack(clip);
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { Clips } from "../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"clips"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account",
|
||||
errors: {
|
||||
noSuchClip: {
|
||||
message: "No such clip.",
|
||||
code: "NO_SUCH_CLIP",
|
||||
id: "70ca08ba-6865-4630-b6fb-8494759aa754"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
clipId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"clipId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
userId: user.id
|
||||
});
|
||||
if (clip == null) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
await Clips.delete(clip.id);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import define from "../../define.js";
|
||||
import { Clips } from "../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"clips",
|
||||
"account"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "read:account",
|
||||
res: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "Clip"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: []
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, me)=>{
|
||||
const clips = await Clips.findBy({
|
||||
userId: me.id
|
||||
});
|
||||
return await Promise.all(clips.map((x)=>Clips.pack(x)));
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
import define from "../../define.js";
|
||||
import { ClipNotes, Clips, Notes } from "../../../../models/index.js";
|
||||
import { makePaginationQuery } from "../../common/make-pagination-query.js";
|
||||
import { generateVisibilityQuery } from "../../common/generate-visibility-query.js";
|
||||
import { generateMutedUserQuery } from "../../common/generate-muted-user-query.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { generateBlockedUserQuery } from "../../common/generate-block-query.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"account",
|
||||
"notes",
|
||||
"clips"
|
||||
],
|
||||
requireCredential: false,
|
||||
requireCredentialPrivateMode: true,
|
||||
kind: "read:account",
|
||||
errors: {
|
||||
noSuchClip: {
|
||||
message: "No such clip.",
|
||||
code: "NO_SUCH_CLIP",
|
||||
id: "1d7645e6-2b6d-4635-b0fe-fe22b0e72e00"
|
||||
}
|
||||
},
|
||||
res: {
|
||||
type: "array",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
items: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "Note"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
clipId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
limit: {
|
||||
type: "integer",
|
||||
minimum: 1,
|
||||
maximum: 100,
|
||||
default: 10
|
||||
},
|
||||
sinceId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
untilId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"clipId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId
|
||||
});
|
||||
if (clip == null) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
if (!clip.isPublic && (user == null || clip.userId !== user.id)) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
const query = makePaginationQuery(Notes.createQueryBuilder("note"), ps.sinceId, ps.untilId).innerJoin(ClipNotes.metadata.targetName, "clipNote", "clipNote.noteId = note.id").innerJoinAndSelect("note.user", "user").leftJoinAndSelect("note.reply", "reply").leftJoinAndSelect("note.renote", "renote").leftJoinAndSelect("reply.user", "replyUser").leftJoinAndSelect("renote.user", "renoteUser").andWhere("clipNote.clipId = :clipId", {
|
||||
clipId: clip.id
|
||||
});
|
||||
if (user) {
|
||||
generateVisibilityQuery(query, user);
|
||||
generateMutedUserQuery(query, user);
|
||||
generateBlockedUserQuery(query, user);
|
||||
}
|
||||
const notes = await query.take(ps.limit).getMany();
|
||||
return await Notes.packMany(notes, user);
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
import define from "../../define.js";
|
||||
import { ClipNotes, Clips } from "../../../../models/index.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { getNote } from "../../common/getters.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"account",
|
||||
"notes",
|
||||
"clips"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account",
|
||||
errors: {
|
||||
noSuchClip: {
|
||||
message: "No such clip.",
|
||||
code: "NO_SUCH_CLIP",
|
||||
id: "b80525c6-97f7-49d7-a42d-ebccd49cfd52"
|
||||
},
|
||||
noSuchNote: {
|
||||
message: "No such note.",
|
||||
code: "NO_SUCH_NOTE",
|
||||
id: "aff017de-190e-434b-893e-33a9ff5049d8"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
clipId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
noteId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"clipId",
|
||||
"noteId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
userId: user.id
|
||||
});
|
||||
if (clip == null) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
const note = await getNote(ps.noteId).catch((e)=>{
|
||||
if (e.id === "9725d0ce-ba28-4dde-95a7-2cbb2c15de24") throw new ApiError(meta.errors.noSuchNote);
|
||||
throw e;
|
||||
});
|
||||
await ClipNotes.delete({
|
||||
noteId: note.id,
|
||||
clipId: clip.id
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { Clips } from "../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"clips",
|
||||
"account"
|
||||
],
|
||||
requireCredential: false,
|
||||
requireCredentialPrivateMode: true,
|
||||
kind: "read:account",
|
||||
errors: {
|
||||
noSuchClip: {
|
||||
message: "No such clip.",
|
||||
code: "NO_SUCH_CLIP",
|
||||
id: "c3c5fe33-d62c-44d2-9ea5-d997703f5c20"
|
||||
}
|
||||
},
|
||||
res: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "Clip"
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
clipId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"clipId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, me)=>{
|
||||
// Fetch the clip
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId
|
||||
});
|
||||
if (clip == null) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
if (!clip.isPublic && (me == null || clip.userId !== me.id)) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
return await Clips.pack(clip);
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import define from "../../define.js";
|
||||
import { ApiError } from "../../error.js";
|
||||
import { Clips } from "../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"clips"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:account",
|
||||
errors: {
|
||||
noSuchClip: {
|
||||
message: "No such clip.",
|
||||
code: "NO_SUCH_CLIP",
|
||||
id: "b4d92d70-b216-46fa-9a3f-a8c811699257"
|
||||
}
|
||||
},
|
||||
res: {
|
||||
type: "object",
|
||||
optional: false,
|
||||
nullable: false,
|
||||
ref: "Clip"
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
clipId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
name: {
|
||||
type: "string",
|
||||
minLength: 1,
|
||||
maxLength: 100
|
||||
},
|
||||
isPublic: {
|
||||
type: "boolean"
|
||||
},
|
||||
description: {
|
||||
type: "string",
|
||||
nullable: true,
|
||||
minLength: 1,
|
||||
maxLength: 2048
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"clipId",
|
||||
"name"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, user)=>{
|
||||
// Fetch the clip
|
||||
const clip = await Clips.findOneBy({
|
||||
id: ps.clipId,
|
||||
userId: user.id
|
||||
});
|
||||
if (clip == null) {
|
||||
throw new ApiError(meta.errors.noSuchClip);
|
||||
}
|
||||
await Clips.update(clip.id, {
|
||||
name: ps.name,
|
||||
description: ps.description,
|
||||
isPublic: ps.isPublic
|
||||
});
|
||||
return await Clips.pack(clip.id);
|
||||
});
|
||||
Reference in New Issue
Block a user