いろいろ変えた
This commit is contained in:
parent
466835a614
commit
db27623f2d
|
@ -27,13 +27,7 @@ import { showMovedDialog } from '@/scripts/show-moved-dialog.js';
|
|||
|
||||
export const openingWindowsCount = ref(0);
|
||||
|
||||
export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req'] = Misskey.Endpoints[E]['req']>(
|
||||
endpoint: E,
|
||||
data: P = {} as any,
|
||||
token?: string | null | undefined,
|
||||
) => {
|
||||
const promise = misskeyApi(endpoint, data, token);
|
||||
promiseDialog(promise, null, async (err) => {
|
||||
export async function apiErrorAlert(err: Misskey.api.APIError, endpoint?: string) {
|
||||
let title: string | undefined;
|
||||
let text = err.message + '\n' + err.id;
|
||||
if (err.code === 'INTERNAL_ERROR') {
|
||||
|
@ -54,7 +48,13 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
|
|||
}],
|
||||
});
|
||||
if (result === 'copy') {
|
||||
copyToClipboard(`Endpoint: ${endpoint}\nInfo: ${JSON.stringify(err.info)}\nDate: ${date}`);
|
||||
const errorReportText = [
|
||||
`Info: ${JSON.stringify(err.info)}`,
|
||||
`Date: ${date}`,
|
||||
];
|
||||
if (endpoint) errorReportText.unshift(`Endpoint: ${endpoint}`);
|
||||
|
||||
copyToClipboard(errorReportText.join('\n'));
|
||||
success();
|
||||
}
|
||||
return;
|
||||
|
@ -79,14 +79,26 @@ export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey
|
|||
title,
|
||||
text,
|
||||
});
|
||||
}
|
||||
|
||||
export const apiWithDialog = (<E extends keyof Misskey.Endpoints = keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req'] = Misskey.Endpoints[E]['req']>(
|
||||
endpoint: E,
|
||||
data: P = {} as any,
|
||||
token?: string | null | undefined,
|
||||
) => {
|
||||
const promise = misskeyApi(endpoint, data, token);
|
||||
promiseDialog(promise, null, (err) => {
|
||||
apiErrorAlert(err);
|
||||
});
|
||||
|
||||
return promise;
|
||||
}) as typeof misskeyApi;
|
||||
|
||||
type Unpromise<T> = T extends Promise<infer U> ? U : never;
|
||||
|
||||
export function promiseDialog<T extends Promise<any>>(
|
||||
promise: T,
|
||||
onSuccess?: ((res: any) => void) | null,
|
||||
onSuccess?: ((res: Unpromise<T>) => void) | null,
|
||||
onFailure?: ((err: Misskey.api.APIError) => void) | null,
|
||||
text?: string,
|
||||
): T {
|
||||
|
|
|
@ -128,6 +128,7 @@ import { defaultStore } from '@/store.js';
|
|||
import { globalEvents } from '@/events.js';
|
||||
import MkInfo from '@/components/MkInfo.vue';
|
||||
import MkTextarea from '@/components/MkTextarea.vue';
|
||||
import { misskeyApi } from '@/scripts/misskey-api.js';
|
||||
|
||||
const $i = signinRequired();
|
||||
|
||||
|
@ -239,13 +240,27 @@ function changeAvatar(ev) {
|
|||
});
|
||||
}
|
||||
|
||||
const i = await os.apiWithDialog('i/update', {
|
||||
const updatePromise = misskeyApi('i/update', {
|
||||
avatarId: originalOrCropped.id,
|
||||
});
|
||||
$i.avatarId = i.avatarId;
|
||||
$i.avatarUrl = i.avatarUrl;
|
||||
|
||||
os.promiseDialog(updatePromise, (updatedUser) => {
|
||||
os.success();
|
||||
$i.avatarId = updatedUser.avatarId;
|
||||
$i.avatarUrl = updatedUser.avatarUrl;
|
||||
globalEvents.emit('requestClearPageCache');
|
||||
claimAchievement('profileFilled');
|
||||
}, (err) => {
|
||||
if (err.code === 'AVATAR_IS_SENSITIVE') {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
title: i18n.ts.cannotSelectSensitiveMedia,
|
||||
text: i18n.ts.cannotSelectSensitiveMediaDescription,
|
||||
});
|
||||
} else {
|
||||
os.apiErrorAlert(err, 'i/update');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -285,12 +300,26 @@ function changeBanner(ev) {
|
|||
});
|
||||
}
|
||||
|
||||
const i = await os.apiWithDialog('i/update', {
|
||||
const updatePromise = misskeyApi('i/update', {
|
||||
bannerId: originalOrCropped.id,
|
||||
});
|
||||
$i.bannerId = i.bannerId;
|
||||
$i.bannerUrl = i.bannerUrl;
|
||||
|
||||
os.promiseDialog(updatePromise, (updatedUser) => {
|
||||
os.success();
|
||||
$i.bannerId = updatedUser.bannerId;
|
||||
$i.bannerUrl = updatedUser.bannerUrl;
|
||||
globalEvents.emit('requestClearPageCache');
|
||||
}, (err) => {
|
||||
if (err.code === 'BANNER_IS_SENSITIVE') {
|
||||
os.alert({
|
||||
type: 'error',
|
||||
title: i18n.ts.cannotSelectSensitiveMedia,
|
||||
text: i18n.ts.cannotSelectSensitiveMediaDescription,
|
||||
});
|
||||
} else {
|
||||
os.apiErrorAlert(err, 'i/update');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import { useStream } from '@/stream.js';
|
|||
import { i18n } from '@/i18n.js';
|
||||
import { defaultStore } from '@/store.js';
|
||||
import { uploadFile } from '@/scripts/upload.js';
|
||||
import { deepMerge } from '@/scripts/merge.js';
|
||||
|
||||
type SelectFileOptions = {
|
||||
multiple?: boolean;
|
||||
|
@ -88,29 +89,18 @@ export function chooseFileFromUrl(): Promise<Misskey.entities.DriveFile> {
|
|||
}
|
||||
|
||||
function select(src: any, label: string | null, options?: SelectFileOptions): Promise<Misskey.entities.DriveFile[]> {
|
||||
const _options = {
|
||||
const _options = deepMerge(options ?? {}, {
|
||||
multiple: false,
|
||||
|
||||
/** ドライブファイル選択時のみに適用 */
|
||||
excludeSensitive: false,
|
||||
additionalMenu: [],
|
||||
...options,
|
||||
};
|
||||
|
||||
additionalMenu: [] as MenuItem[],
|
||||
});
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
const keepOriginal = ref(defaultStore.state.keepOriginalUploading);
|
||||
|
||||
function _resolve(files: Misskey.entities.DriveFile[]) {
|
||||
if (_options.excludeSensitive && files.some(file => file.isSensitive)) {
|
||||
os.alert({
|
||||
title: i18n.ts.cannotSelectSensitiveMedia,
|
||||
text: i18n.ts.cannotSelectSensitiveMediaDescription,
|
||||
});
|
||||
rej(new Error('Sensitive media is selected'));
|
||||
return;
|
||||
}
|
||||
|
||||
res(files);
|
||||
}
|
||||
|
||||
os.popupMenu([label ? {
|
||||
text: label,
|
||||
type: 'label',
|
||||
|
@ -121,23 +111,23 @@ function select(src: any, label: string | null, options?: SelectFileOptions): Pr
|
|||
}, {
|
||||
text: i18n.ts.upload,
|
||||
icon: 'ti ti-upload',
|
||||
action: () => chooseFileFromPc(_options.multiple, keepOriginal.value).then(files => _resolve(files)),
|
||||
action: () => chooseFileFromPc(_options.multiple, keepOriginal.value).then(files => res(files)),
|
||||
}, {
|
||||
text: i18n.ts.fromDrive,
|
||||
icon: 'ti ti-cloud',
|
||||
action: () => chooseFileFromDrive(_options.multiple, _options.excludeSensitive).then(files => _resolve(files)),
|
||||
action: () => chooseFileFromDrive(_options.multiple, _options.excludeSensitive).then(files => res(files)),
|
||||
}, {
|
||||
text: i18n.ts.fromUrl,
|
||||
icon: 'ti ti-link',
|
||||
action: () => chooseFileFromUrl().then(file => _resolve([file])),
|
||||
}, ..._options.additionalMenu], src);
|
||||
action: () => chooseFileFromUrl().then(file => res([file])),
|
||||
}, ...(_options.additionalMenu)], src);
|
||||
});
|
||||
}
|
||||
|
||||
export function selectFile(src: any, label: string | null = null, options?: { excludeSensitive?: boolean; additionalMenu?: MenuItem[]; }): Promise<Misskey.entities.DriveFile> {
|
||||
return select(src, label, { ...options, multiple: false }).then(files => files[0]);
|
||||
return select(src, label, { ...(options ? options : {}), multiple: false }).then(files => files[0]);
|
||||
}
|
||||
|
||||
export function selectFiles(src: any, label: string | null = null, options?: { excludeSensitive?: boolean; additionalMenu?: MenuItem[]; }): Promise<Misskey.entities.DriveFile[]> {
|
||||
return select(src, label, { ...options, multiple: true });
|
||||
return select(src, label, { ...(options ? options : {}), multiple: true });
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue