Merge remote-tracking branch 'misskey-dev/develop' into io
This commit is contained in:
commit
e756272c02
1855 changed files with 2327 additions and 1948 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
|
@ -124,9 +124,9 @@ export function randomString(chars = 'abcdefghijklmnopqrstuvwxyz0123456789', len
|
|||
function timeoutPromise<T>(p: Promise<T>, timeout: number): Promise<T> {
|
||||
return Promise.race([
|
||||
p,
|
||||
new Promise((reject) =>{
|
||||
setTimeout(() => { reject(new Error('timed out')); }, timeout)
|
||||
}) as never
|
||||
new Promise((reject) => {
|
||||
setTimeout(() => { reject(new Error('timed out')); }, timeout);
|
||||
}) as never,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -344,7 +344,7 @@ export const uploadUrl = async (user: UserToken, url: string): Promise<Packed<'D
|
|||
'main',
|
||||
(msg) => msg.type === 'urlUploadFinished' && msg.body.marker === marker,
|
||||
(msg) => msg.body.file as Packed<'DriveFile'>,
|
||||
60 * 1000
|
||||
60 * 1000,
|
||||
);
|
||||
|
||||
await api('drive/files/upload-from-url', {
|
||||
|
@ -435,20 +435,20 @@ export const waitFire = async (user: UserToken, channel: string, trgr: () => any
|
|||
* @returns 時間内に正常に処理できた場合に通知からextractorを通した値を得る
|
||||
*/
|
||||
export function makeStreamCatcher<T>(
|
||||
user: UserToken,
|
||||
channel: string,
|
||||
cond: (message: Record<string, any>) => boolean,
|
||||
extractor: (message: Record<string, any>) => T,
|
||||
timeout = 60 * 1000): Promise<T> {
|
||||
let ws: WebSocket
|
||||
user: UserToken,
|
||||
channel: string,
|
||||
cond: (message: Record<string, any>) => boolean,
|
||||
extractor: (message: Record<string, any>) => T,
|
||||
timeout = 60 * 1000): Promise<T> {
|
||||
let ws: WebSocket;
|
||||
const p = new Promise<T>(async (resolve) => {
|
||||
ws = await connectStream(user, channel, (msg) => {
|
||||
if (cond(msg)) {
|
||||
resolve(extractor(msg))
|
||||
resolve(extractor(msg));
|
||||
}
|
||||
});
|
||||
}).finally(() => {
|
||||
ws?.close();
|
||||
ws.close();
|
||||
});
|
||||
|
||||
return timeoutPromise(p, timeout);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue