Fixed 267U.pre2
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
import define from "../../../../define.js";
|
||||
import { ApiError } from "../../../../error.js";
|
||||
import { DriveFiles, UserEmojis, UserGroups } from "../../../../../../models/index.js";
|
||||
import { genId } from "../../../../../../misc/gen-id.js";
|
||||
import { getEmojiSize } from "../../../../../../misc/emoji-meta.js";
|
||||
import { clearGroupEmojiCache } from "../../../../../../misc/populate-emojis.js";
|
||||
function normalizeMimeType(type) {
|
||||
const mime = type?.split(";")[0]?.trim().toLowerCase();
|
||||
return mime && mime.length <= 64 ? mime : null;
|
||||
}
|
||||
export const meta = {
|
||||
tags: [
|
||||
"groups"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:user-groups",
|
||||
errors: {
|
||||
noSuchGroup: {
|
||||
message: "No such group.",
|
||||
code: "NO_SUCH_GROUP",
|
||||
id: "ab752eba-3f77-4746-b805-1457719f648d"
|
||||
},
|
||||
noSuchFile: {
|
||||
message: "No such file.",
|
||||
code: "NO_SUCH_FILE",
|
||||
id: "be2812bf-55c0-4fd9-8d1b-813578fc81f9"
|
||||
},
|
||||
alreadyExists: {
|
||||
message: "Group emoji already exists.",
|
||||
code: "ALREADY_EXISTS",
|
||||
id: "7957d717-e009-47c8-b32d-37a13afed4db"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
groupId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
name: {
|
||||
type: "string",
|
||||
pattern: "^[a-z0-9_]{1,64}$"
|
||||
},
|
||||
fileId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
},
|
||||
glyph: {
|
||||
type: "boolean",
|
||||
default: false
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"groupId",
|
||||
"name",
|
||||
"fileId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, me)=>{
|
||||
const group = await UserGroups.findOneBy({
|
||||
id: ps.groupId,
|
||||
userId: me.id
|
||||
});
|
||||
if (!group) throw new ApiError(meta.errors.noSuchGroup);
|
||||
const file = await DriveFiles.findOneBy({
|
||||
id: ps.fileId,
|
||||
userId: me.id
|
||||
});
|
||||
if (!file || !file.type.startsWith("image/")) throw new ApiError(meta.errors.noSuchFile);
|
||||
const exists = await UserEmojis.findOneBy({
|
||||
name: ps.name,
|
||||
userGroupId: group.id
|
||||
});
|
||||
if (exists) throw new ApiError(meta.errors.alreadyExists);
|
||||
const size = await getEmojiSize(file.url).catch(()=>({
|
||||
width: null,
|
||||
height: null
|
||||
}));
|
||||
const emoji = await UserEmojis.insert({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
name: ps.name,
|
||||
userId: null,
|
||||
userGroupId: group.id,
|
||||
originalUrl: file.url,
|
||||
publicUrl: file.webpublicUrl ?? file.url,
|
||||
type: normalizeMimeType(file.webpublicType ?? file.type),
|
||||
glyph: ps.glyph,
|
||||
width: size.width || null,
|
||||
height: size.height || null
|
||||
}).then((x)=>UserEmojis.findOneByOrFail(x.identifiers[0]));
|
||||
await clearGroupEmojiCache(emoji.name, group.username);
|
||||
return {
|
||||
id: emoji.id,
|
||||
name: emoji.name,
|
||||
url: emoji.publicUrl || emoji.originalUrl,
|
||||
glyph: emoji.glyph,
|
||||
glyphUrl: emoji.glyph ? emoji.originalUrl : null,
|
||||
width: emoji.width,
|
||||
height: emoji.height
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
import define from "../../../../define.js";
|
||||
import { ApiError } from "../../../../error.js";
|
||||
import { UserEmojis, UserGroups } from "../../../../../../models/index.js";
|
||||
import { clearGroupEmojiCache } from "../../../../../../misc/populate-emojis.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"groups"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "write:user-groups",
|
||||
errors: {
|
||||
noSuchEmoji: {
|
||||
message: "No such group emoji.",
|
||||
code: "NO_SUCH_GROUP_EMOJI",
|
||||
id: "e22d8bd7-d9c5-4470-8ef0-9a9095985b3f"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
id: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"id"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, me)=>{
|
||||
const emoji = await UserEmojis.findOneBy({
|
||||
id: ps.id
|
||||
});
|
||||
if (!emoji?.userGroupId) throw new ApiError(meta.errors.noSuchEmoji);
|
||||
const group = await UserGroups.findOneBy({
|
||||
id: emoji.userGroupId,
|
||||
userId: me.id
|
||||
});
|
||||
if (!group) throw new ApiError(meta.errors.noSuchEmoji);
|
||||
await UserEmojis.delete(emoji.id);
|
||||
await clearGroupEmojiCache(emoji.name, group.username);
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import define from "../../../../define.js";
|
||||
import { ApiError } from "../../../../error.js";
|
||||
import { UserEmojis, UserGroupJoinings, UserGroups } from "../../../../../../models/index.js";
|
||||
export const meta = {
|
||||
tags: [
|
||||
"groups"
|
||||
],
|
||||
requireCredential: true,
|
||||
kind: "read:user-groups",
|
||||
errors: {
|
||||
noSuchGroup: {
|
||||
message: "No such group.",
|
||||
code: "NO_SUCH_GROUP",
|
||||
id: "e9f78109-710a-44fd-8ab2-51582f65dd97"
|
||||
}
|
||||
}
|
||||
};
|
||||
export const paramDef = {
|
||||
type: "object",
|
||||
properties: {
|
||||
groupId: {
|
||||
type: "string",
|
||||
format: "misskey:id"
|
||||
}
|
||||
},
|
||||
required: [
|
||||
"groupId"
|
||||
]
|
||||
};
|
||||
export default define(meta, paramDef, async (ps, me)=>{
|
||||
const group = await UserGroups.findOneBy({
|
||||
id: ps.groupId
|
||||
});
|
||||
if (!group) throw new ApiError(meta.errors.noSuchGroup);
|
||||
const member = await UserGroupJoinings.findOneBy({
|
||||
userGroupId: group.id,
|
||||
userId: me.id
|
||||
});
|
||||
if (group.userId !== me.id && !member) throw new ApiError(meta.errors.noSuchGroup);
|
||||
const emojis = await UserEmojis.find({
|
||||
where: {
|
||||
userGroupId: group.id
|
||||
},
|
||||
order: {
|
||||
createdAt: "DESC"
|
||||
}
|
||||
});
|
||||
return emojis.map((emoji)=>({
|
||||
id: emoji.id,
|
||||
name: emoji.name,
|
||||
url: emoji.publicUrl || emoji.originalUrl,
|
||||
glyph: emoji.glyph,
|
||||
glyphUrl: emoji.glyph ? emoji.originalUrl : null,
|
||||
width: emoji.width,
|
||||
height: emoji.height
|
||||
}));
|
||||
});
|
||||
Reference in New Issue
Block a user