Merge remote-tracking branch 'misskey-dev/develop' into io
This commit is contained in:
commit
9e63703d59
35 changed files with 1455 additions and 1309 deletions
|
@ -9,12 +9,11 @@ import { basename, isAbsolute } from 'node:path';
|
|||
import { randomUUID } from 'node:crypto';
|
||||
import { inspect } from 'node:util';
|
||||
import WebSocket, { ClientOptions } from 'ws';
|
||||
import fetch, { File, RequestInit } from 'node-fetch';
|
||||
import fetch, { File, RequestInit, type Headers } from 'node-fetch';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import * as Redis from 'ioredis';
|
||||
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
|
||||
import { Packed } from '@/misc/json-schema.js';
|
||||
import { validateContentTypeSetAsActivityPub } from '@/core/activitypub/misc/validator.js';
|
||||
import { entities } from '@/postgres.js';
|
||||
import { loadConfig } from '@/config.js';
|
||||
|
@ -22,7 +21,7 @@ import type * as misskey from 'misskey-js';
|
|||
|
||||
export { server as startServer, jobQueue as startJobQueue } from '@/boot/common.js';
|
||||
|
||||
interface UserToken {
|
||||
export interface UserToken {
|
||||
token: string;
|
||||
bearer?: boolean;
|
||||
}
|
||||
|
@ -36,20 +35,15 @@ export const cookie = (me: UserToken): string => {
|
|||
return `token=${me.token};`;
|
||||
};
|
||||
|
||||
export const api = async (endpoint: string, params: any, me?: UserToken) => {
|
||||
const normalized = endpoint.replace(/^\//, '');
|
||||
return await request(`api/${normalized}`, params, me);
|
||||
};
|
||||
|
||||
export type ApiRequest = {
|
||||
endpoint: string,
|
||||
parameters: object,
|
||||
export type ApiRequest<E extends keyof misskey.Endpoints, P extends misskey.Endpoints[E]['req'] = misskey.Endpoints[E]['req']> = {
|
||||
endpoint: E,
|
||||
parameters: P,
|
||||
user: UserToken | undefined,
|
||||
};
|
||||
|
||||
export const successfulApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
export const successfulApiCall = async <E extends keyof misskey.Endpoints, P extends misskey.Endpoints[E]['req']>(request: ApiRequest<E, P>, assertion: {
|
||||
status?: number,
|
||||
} = {}): Promise<T> => {
|
||||
} = {}): Promise<misskey.api.SwitchCaseResponseType<E, P>> => {
|
||||
const { endpoint, parameters, user } = request;
|
||||
const res = await api(endpoint, parameters, user);
|
||||
const status = assertion.status ?? (res.body == null ? 204 : 200);
|
||||
|
@ -57,7 +51,7 @@ export const successfulApiCall = async <T, >(request: ApiRequest, assertion: {
|
|||
return res.body;
|
||||
};
|
||||
|
||||
export const failedApiCall = async <T, >(request: ApiRequest, assertion: {
|
||||
export const failedApiCall = async <T, E extends keyof misskey.Endpoints, P extends misskey.Endpoints[E]['req']>(request: ApiRequest<E, P>, assertion: {
|
||||
status: number,
|
||||
code: string,
|
||||
id: string
|
||||
|
@ -71,7 +65,7 @@ export const failedApiCall = async <T, >(request: ApiRequest, assertion: {
|
|||
return res.body;
|
||||
};
|
||||
|
||||
const request = async (path: string, params: any, me?: UserToken): Promise<{
|
||||
export const api = async <E extends keyof misskey.Endpoints>(path: E, params: misskey.Endpoints[E]['req'], me?: UserToken): Promise<{
|
||||
status: number,
|
||||
headers: Headers,
|
||||
body: any
|
||||
|
@ -87,7 +81,7 @@ const request = async (path: string, params: any, me?: UserToken): Promise<{
|
|||
bodyAuth.i = me.token;
|
||||
}
|
||||
|
||||
const res = await relativeFetch(path, {
|
||||
const res = await relativeFetch(`api/${path}`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify(Object.assign(bodyAuth, params)),
|
||||
|
@ -142,7 +136,7 @@ export const signup = async (params?: Partial<misskey.Endpoints['signup']['req']
|
|||
return res.body;
|
||||
};
|
||||
|
||||
export const post = async (user: UserToken, params?: misskey.Endpoints['notes/create']['req']): Promise<misskey.entities.Note> => {
|
||||
export const post = async (user: UserToken, params: misskey.Endpoints['notes/create']['req']): Promise<misskey.entities.Note> => {
|
||||
const q = params;
|
||||
|
||||
const res = await api('notes/create', q, user);
|
||||
|
@ -160,8 +154,8 @@ export const createAppToken = async (user: UserToken, permissions: (typeof missk
|
|||
};
|
||||
|
||||
// 非公開ノートをAPI越しに見たときのノート NoteEntityService.ts
|
||||
export const hiddenNote = (note: any): any => {
|
||||
const temp = {
|
||||
export const hiddenNote = (note: misskey.entities.Note): misskey.entities.Note => {
|
||||
const temp: misskey.entities.Note = {
|
||||
...note,
|
||||
fileIds: [],
|
||||
files: [],
|
||||
|
@ -174,21 +168,22 @@ export const hiddenNote = (note: any): any => {
|
|||
return temp;
|
||||
};
|
||||
|
||||
export const react = async (user: UserToken, note: any, reaction: string): Promise<any> => {
|
||||
export const react = async (user: UserToken, note: misskey.entities.Note, reaction: string): Promise<void> => {
|
||||
await api('notes/reactions/create', {
|
||||
noteId: note.id,
|
||||
reaction: reaction,
|
||||
}, user);
|
||||
};
|
||||
|
||||
export const userList = async (user: UserToken, userList: any = {}): Promise<any> => {
|
||||
export const userList = async (user: UserToken, userList: Partial<misskey.entities.UserList> = {}): Promise<misskey.entities.UserList> => {
|
||||
const res = await api('users/lists/create', {
|
||||
name: 'test',
|
||||
...userList,
|
||||
}, user);
|
||||
return res.body;
|
||||
};
|
||||
|
||||
export const page = async (user: UserToken, page: any = {}): Promise<any> => {
|
||||
export const page = async (user: UserToken, page: Partial<misskey.entities.Page> = {}): Promise<misskey.entities.Page> => {
|
||||
const res = await api('pages/create', {
|
||||
alignCenter: false,
|
||||
content: [
|
||||
|
@ -199,7 +194,7 @@ export const page = async (user: UserToken, page: any = {}): Promise<any> => {
|
|||
},
|
||||
],
|
||||
eyeCatchingImageId: null,
|
||||
font: 'sans-serif',
|
||||
font: 'sans-serif' as any,
|
||||
hideTitleWhenPinned: false,
|
||||
name: '1678594845072',
|
||||
script: '',
|
||||
|
@ -211,7 +206,7 @@ export const page = async (user: UserToken, page: any = {}): Promise<any> => {
|
|||
return res.body;
|
||||
};
|
||||
|
||||
export const play = async (user: UserToken, play: any = {}): Promise<any> => {
|
||||
export const play = async (user: UserToken, play: Partial<misskey.entities.Flash> = {}): Promise<misskey.entities.Flash> => {
|
||||
const res = await api('flash/create', {
|
||||
permissions: [],
|
||||
script: 'test',
|
||||
|
@ -222,7 +217,7 @@ export const play = async (user: UserToken, play: any = {}): Promise<any> => {
|
|||
return res.body;
|
||||
};
|
||||
|
||||
export const clip = async (user: UserToken, clip: any = {}): Promise<any> => {
|
||||
export const clip = async (user: UserToken, clip: Partial<misskey.entities.Clip> = {}): Promise<misskey.entities.Clip> => {
|
||||
const res = await api('clips/create', {
|
||||
description: null,
|
||||
isPublic: true,
|
||||
|
@ -232,18 +227,18 @@ export const clip = async (user: UserToken, clip: any = {}): Promise<any> => {
|
|||
return res.body;
|
||||
};
|
||||
|
||||
export const galleryPost = async (user: UserToken, channel: any = {}): Promise<any> => {
|
||||
export const galleryPost = async (user: UserToken, galleryPost: Partial<misskey.entities.GalleryPost> = {}): Promise<misskey.entities.GalleryPost> => {
|
||||
const res = await api('gallery/posts/create', {
|
||||
description: null,
|
||||
fileIds: [],
|
||||
isSensitive: false,
|
||||
title: 'test',
|
||||
...channel,
|
||||
...galleryPost,
|
||||
}, user);
|
||||
return res.body;
|
||||
};
|
||||
|
||||
export const channel = async (user: UserToken, channel: any = {}): Promise<any> => {
|
||||
export const channel = async (user: UserToken, channel: Partial<misskey.entities.Channel> = {}): Promise<misskey.entities.Channel> => {
|
||||
const res = await api('channels/create', {
|
||||
bannerId: null,
|
||||
description: null,
|
||||
|
@ -253,7 +248,7 @@ export const channel = async (user: UserToken, channel: any = {}): Promise<any>
|
|||
return res.body;
|
||||
};
|
||||
|
||||
export const role = async (user: UserToken, role: any = {}, policies: any = {}): Promise<any> => {
|
||||
export const role = async (user: UserToken, role: Partial<misskey.entities.Role> = {}, policies: any = {}): Promise<misskey.entities.Role> => {
|
||||
const res = await api('admin/roles/create', {
|
||||
asBadge: false,
|
||||
canEditMembersByModerator: false,
|
||||
|
@ -261,7 +256,7 @@ export const role = async (user: UserToken, role: any = {}, policies: any = {}):
|
|||
condFormula: {
|
||||
id: 'ebef1684-672d-49b6-ad82-1b3ec3784f85',
|
||||
type: 'isRemote',
|
||||
},
|
||||
} as any,
|
||||
description: '',
|
||||
displayOrder: 0,
|
||||
iconUrl: null,
|
||||
|
@ -299,7 +294,7 @@ interface UploadOptions {
|
|||
export const uploadFile = async (user?: UserToken, { path, name, blob }: UploadOptions = {}): Promise<{
|
||||
status: number,
|
||||
headers: Headers,
|
||||
body: misskey.Endpoints['drive/files/create']['res'] | null
|
||||
body: misskey.entities.DriveFile | null
|
||||
}> => {
|
||||
const absPath = path == null
|
||||
? new URL('resources/Lenna.jpg', import.meta.url)
|
||||
|
@ -336,14 +331,14 @@ export const uploadFile = async (user?: UserToken, { path, name, blob }: UploadO
|
|||
};
|
||||
};
|
||||
|
||||
export const uploadUrl = async (user: UserToken, url: string): Promise<Packed<'DriveFile'>> => {
|
||||
export const uploadUrl = async (user: UserToken, url: string): Promise<misskey.entities.DriveFile> => {
|
||||
const marker = Math.random().toString();
|
||||
|
||||
const catcher = makeStreamCatcher(
|
||||
user,
|
||||
'main',
|
||||
(msg) => msg.type === 'urlUploadFinished' && msg.body.marker === marker,
|
||||
(msg) => msg.body.file as Packed<'DriveFile'>,
|
||||
(msg) => msg.body.file,
|
||||
60 * 1000,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue