Fixed 267U.pre2

This commit is contained in:
2026-07-26 18:25:37 +09:00
parent 50bfaeafdf
commit 317d00a284
1286 changed files with 80222 additions and 1 deletions
@@ -0,0 +1,69 @@
import define from "../../define.js";
import { ApiError } from "../../error.js";
import { Channels, DriveFiles } from "../../../../models/index.js";
import { genId } from "../../../../misc/gen-id.js";
export const meta = {
tags: [
"channels"
],
requireCredential: true,
kind: "write:channels",
res: {
type: "object",
optional: false,
nullable: false,
ref: "Channel"
},
errors: {
noSuchFile: {
message: "No such file.",
code: "NO_SUCH_FILE",
id: "cd1e9f3e-5a12-4ab4-96f6-5d0a2cc32050"
}
}
};
export const paramDef = {
type: "object",
properties: {
name: {
type: "string",
minLength: 1,
maxLength: 128
},
description: {
type: "string",
nullable: true,
minLength: 1,
maxLength: 2048
},
bannerId: {
type: "string",
format: "misskey:id",
nullable: true
}
},
required: [
"name"
]
};
export default define(meta, paramDef, async (ps, user)=>{
let banner = null;
if (ps.bannerId != null) {
banner = await DriveFiles.findOneBy({
id: ps.bannerId,
userId: user.id
});
if (banner == null) {
throw new ApiError(meta.errors.noSuchFile);
}
}
const channel = await Channels.insert({
id: genId(),
createdAt: new Date(),
userId: user.id,
name: ps.name,
description: ps.description || null,
bannerId: banner ? banner.id : null
}).then((x)=>Channels.findOneByOrFail(x.identifiers[0]));
return await Channels.pack(channel, user);
});
@@ -0,0 +1,29 @@
import define from "../../define.js";
import { Channels } from "../../../../models/index.js";
export const meta = {
tags: [
"channels"
],
requireCredential: true,
res: {
type: "array",
optional: false,
nullable: false,
items: {
type: "object",
optional: false,
nullable: false,
ref: "Channel"
}
}
};
export const paramDef = {
type: "object",
properties: {},
required: []
};
export default define(meta, paramDef, async (ps, me)=>{
const query = Channels.createQueryBuilder("channel").where("channel.lastNotedAt IS NOT NULL").orderBy("channel.lastNotedAt", "DESC");
const channels = await query.take(10).getMany();
return await Promise.all(channels.map((x)=>Channels.pack(x, me)));
});
@@ -0,0 +1,46 @@
import define from "../../define.js";
import { ApiError } from "../../error.js";
import { Channels, ChannelFollowings } from "../../../../models/index.js";
import { genId } from "../../../../misc/gen-id.js";
import { publishUserEvent } from "../../../../services/stream.js";
export const meta = {
tags: [
"channels"
],
requireCredential: true,
kind: "write:channels",
errors: {
noSuchChannel: {
message: "No such channel.",
code: "NO_SUCH_CHANNEL",
id: "c0031718-d573-4e85-928e-10039f1fbb68"
}
}
};
export const paramDef = {
type: "object",
properties: {
channelId: {
type: "string",
format: "misskey:id"
}
},
required: [
"channelId"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const channel = await Channels.findOneBy({
id: ps.channelId
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
await ChannelFollowings.insert({
id: genId(),
createdAt: new Date(),
followerId: user.id,
followeeId: channel.id
});
publishUserEvent(user.id, "followChannel", channel);
});
@@ -0,0 +1,63 @@
import define from "../../define.js";
import { Channels, ChannelFollowings } from "../../../../models/index.js";
export const meta = {
tags: [
"channels",
"account"
],
requireCredential: true,
kind: "read:channels",
res: {
type: "array",
optional: false,
nullable: false,
items: {
type: "object",
optional: false,
nullable: false,
ref: "Channel"
}
}
};
export const paramDef = {
type: "object",
properties: {
sinceId: {
type: "string",
format: "misskey:id"
},
untilId: {
type: "string",
format: "misskey:id"
},
limit: {
type: "integer",
minimum: 1,
maximum: 100,
default: 5
}
},
required: []
};
export default define(meta, paramDef, async (ps, me)=>{
const query = ChannelFollowings.createQueryBuilder("following").andWhere({
followerId: me.id
});
if (ps.sinceId) {
query.andWhere('following."followeeId" > :sinceId', {
sinceId: ps.sinceId
});
}
if (ps.untilId) {
query.andWhere('following."followeeId" < :untilId', {
untilId: ps.untilId
});
}
if (ps.sinceId && !ps.untilId) {
query.orderBy('following."followeeId"', "ASC");
} else {
query.orderBy('following."followeeId"', "DESC");
}
const followings = await query.take(ps.limit).getMany();
return await Promise.all(followings.map((x)=>Channels.pack(x.followeeId, me)));
});
@@ -0,0 +1,49 @@
import define from "../../define.js";
import { Channels } from "../../../../models/index.js";
import { makePaginationQuery } from "../../common/make-pagination-query.js";
export const meta = {
tags: [
"channels",
"account"
],
requireCredential: true,
kind: "read:channels",
res: {
type: "array",
optional: false,
nullable: false,
items: {
type: "object",
optional: false,
nullable: false,
ref: "Channel"
}
}
};
export const paramDef = {
type: "object",
properties: {
sinceId: {
type: "string",
format: "misskey:id"
},
untilId: {
type: "string",
format: "misskey:id"
},
limit: {
type: "integer",
minimum: 1,
maximum: 100,
default: 5
}
},
required: []
};
export default define(meta, paramDef, async (ps, me)=>{
const query = makePaginationQuery(Channels.createQueryBuilder(), ps.sinceId, ps.untilId).andWhere({
userId: me.id
});
const channels = await query.take(ps.limit).getMany();
return await Promise.all(channels.map((x)=>Channels.pack(x, me)));
});
@@ -0,0 +1,73 @@
import define from "../../define.js";
import { Brackets } from "typeorm";
import { makePaginationQuery } from "../../common/make-pagination-query.js";
import { Channels } from "../../../../models/index.js";
import { sqlLikeEscape } from "../../../../misc/sql-like-escape.js";
export const meta = {
tags: [
"channels"
],
requireCredential: true,
res: {
type: "array",
optional: false,
nullable: false,
items: {
type: "object",
optional: false,
nullable: false,
ref: "Channel"
}
}
};
export const paramDef = {
type: "object",
properties: {
query: {
type: "string"
},
type: {
type: "string",
enum: [
"nameAndDescription",
"nameOnly"
],
default: "nameAndDescription"
},
sinceId: {
type: "string",
format: "misskey:id"
},
untilId: {
type: "string",
format: "misskey:id"
},
limit: {
type: "integer",
minimum: 1,
maximum: 100,
default: 5
}
},
required: [
"query"
]
};
export default define(meta, paramDef, async (ps, me)=>{
const query = makePaginationQuery(Channels.createQueryBuilder("channel"), ps.sinceId, ps.untilId);
if (ps.type === "nameAndDescription") {
query.andWhere(new Brackets((qb)=>{
qb.where("channel.name ILIKE :q", {
q: `%${sqlLikeEscape(ps.query)}%`
}).orWhere("channel.description ILIKE :q", {
q: `%${sqlLikeEscape(ps.query)}%`
});
}));
} else {
query.andWhere("channel.name ILIKE :q", {
q: `%${sqlLikeEscape(ps.query)}%`
});
}
const channels = await query.take(ps.limit).getMany();
return await Promise.all(channels.map((x)=>Channels.pack(x, me)));
});
@@ -0,0 +1,43 @@
import define from "../../define.js";
import { ApiError } from "../../error.js";
import { Channels } from "../../../../models/index.js";
export const meta = {
tags: [
"channels"
],
requireCredential: true,
res: {
type: "object",
optional: false,
nullable: false,
ref: "Channel"
},
errors: {
noSuchChannel: {
message: "No such channel.",
code: "NO_SUCH_CHANNEL",
id: "6f6c314b-7486-4897-8966-c04a66a02923"
}
}
};
export const paramDef = {
type: "object",
properties: {
channelId: {
type: "string",
format: "misskey:id"
}
},
required: [
"channelId"
]
};
export default define(meta, paramDef, async (ps, me)=>{
const channel = await Channels.findOneBy({
id: ps.channelId
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
return await Channels.pack(channel, me);
});
@@ -0,0 +1,80 @@
import define from "../../define.js";
import { ApiError } from "../../error.js";
import { Notes, Channels } from "../../../../models/index.js";
import { makePaginationQuery } from "../../common/make-pagination-query.js";
import { activeUsersChart } from "../../../../services/chart/index.js";
import { generateExcludeMemorietQuery } from "../../common/generate-exclude-memoriet-query.js";
export const meta = {
tags: [
"notes",
"channels"
],
requireCredential: true,
res: {
type: "array",
optional: false,
nullable: false,
items: {
type: "object",
optional: false,
nullable: false,
ref: "Note"
}
},
errors: {
noSuchChannel: {
message: "No such channel.",
code: "NO_SUCH_CHANNEL",
id: "4d0eeeba-a02c-4c3c-9966-ef60d38d2e7f"
}
}
};
export const paramDef = {
type: "object",
properties: {
channelId: {
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"
},
sinceDate: {
type: "integer"
},
untilDate: {
type: "integer"
}
},
required: [
"channelId"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const channel = await Channels.findOneBy({
id: ps.channelId
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
//#region Construct query
const query = makePaginationQuery(Notes.createQueryBuilder("note"), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate).andWhere("note.channelId = :channelId", {
channelId: channel.id
}).innerJoinAndSelect("note.user", "user").leftJoinAndSelect("note.reply", "reply").leftJoinAndSelect("note.renote", "renote").leftJoinAndSelect("reply.user", "replyUser").leftJoinAndSelect("renote.user", "renoteUser").leftJoinAndSelect("note.channel", "channel");
generateExcludeMemorietQuery(query);
//#endregion
const timeline = await query.take(ps.limit).getMany();
if (user) activeUsersChart.read(user);
return await Notes.packMany(timeline, user);
});
@@ -0,0 +1,43 @@
import define from "../../define.js";
import { ApiError } from "../../error.js";
import { Channels, ChannelFollowings } from "../../../../models/index.js";
import { publishUserEvent } from "../../../../services/stream.js";
export const meta = {
tags: [
"channels"
],
requireCredential: true,
kind: "write:channels",
errors: {
noSuchChannel: {
message: "No such channel.",
code: "NO_SUCH_CHANNEL",
id: "19959ee9-0153-4c51-bbd9-a98c49dc59d6"
}
}
};
export const paramDef = {
type: "object",
properties: {
channelId: {
type: "string",
format: "misskey:id"
}
},
required: [
"channelId"
]
};
export default define(meta, paramDef, async (ps, user)=>{
const channel = await Channels.findOneBy({
id: ps.channelId
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
await ChannelFollowings.delete({
followerId: user.id,
followeeId: channel.id
});
publishUserEvent(user.id, "unfollowChannel", channel);
});
@@ -0,0 +1,96 @@
import define from "../../define.js";
import { ApiError } from "../../error.js";
import { Channels, DriveFiles } from "../../../../models/index.js";
export const meta = {
tags: [
"channels"
],
requireCredential: true,
kind: "write:channels",
res: {
type: "object",
optional: false,
nullable: false,
ref: "Channel"
},
errors: {
noSuchChannel: {
message: "No such channel.",
code: "NO_SUCH_CHANNEL",
id: "f9c5467f-d492-4c3c-9a8d-a70dacc86512"
},
accessDenied: {
message: "You do not have edit privilege of the channel.",
code: "ACCESS_DENIED",
id: "1fb7cb09-d46a-4fdf-b8df-057788cce513"
},
noSuchFile: {
message: "No such file.",
code: "NO_SUCH_FILE",
id: "e86c14a4-0da2-4032-8df3-e737a04c7f3b"
}
}
};
export const paramDef = {
type: "object",
properties: {
channelId: {
type: "string",
format: "misskey:id"
},
name: {
type: "string",
minLength: 1,
maxLength: 128
},
description: {
type: "string",
nullable: true,
minLength: 1,
maxLength: 2048
},
bannerId: {
type: "string",
format: "misskey:id",
nullable: true
}
},
required: [
"channelId"
]
};
export default define(meta, paramDef, async (ps, me)=>{
const channel = await Channels.findOneBy({
id: ps.channelId
});
if (channel == null) {
throw new ApiError(meta.errors.noSuchChannel);
}
if (channel.userId !== me.id) {
throw new ApiError(meta.errors.accessDenied);
}
let banner = undefined;
if (ps.bannerId != null) {
banner = await DriveFiles.findOneBy({
id: ps.bannerId,
userId: me.id
});
if (banner == null) {
throw new ApiError(meta.errors.noSuchFile);
}
} else if (ps.bannerId === null) {
banner = null;
}
await Channels.update(channel.id, {
...ps.name !== undefined ? {
name: ps.name
} : {},
...ps.description !== undefined ? {
description: ps.description
} : {},
...banner ? {
bannerId: banner.id
} : {}
});
return await Channels.pack(channel.id, me);
});