refactor(frontend): os.tsに引き込んだscripts/api.tsの再exportをやめる (#12694)

* refactor(frontend): os.tsに引き込んだscripts/api.tsの再exportをやめる

* fix

* fix

* renate to "misskeyApi"

* rename file
This commit is contained in:
おさむのひと
2024-01-04 18:32:46 +09:00
committed by GitHub
parent ea41cc6ec0
commit fa9c4a19b9
191 changed files with 581 additions and 468 deletions

View File

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { $i } from '@/account.js';
export const ACHIEVEMENT_TYPES = [
@@ -489,7 +489,7 @@ export async function claimAchievement(type: typeof ACHIEVEMENT_TYPES[number]) {
window.setTimeout(() => {
claimingQueue.delete(type);
}, 500);
os.api('i/claim-achievement', { name: type });
misskeyApi('i/claim-achievement', { name: type });
}
if (_DEV_) {

View File

@@ -5,6 +5,7 @@
import { utils, values } from '@syuilo/aiscript';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { $i } from '@/account.js';
import { miLocalStorage } from '@/local-storage.js';
import { customEmojis } from '@/custom-emojis.js';
@@ -54,7 +55,7 @@ export function createAiScriptEnv(opts) {
if (typeof token.value !== 'string') throw new Error('invalid token');
}
const actualToken: string|null = token?.value ?? opts.token ?? null;
return os.api(ep.value, utils.valToJs(param), actualToken).then(res => {
return misskeyApi(ep.value, utils.valToJs(param), actualToken).then(res => {
return utils.jsToVal(res);
}, err => {
return values.ERROR('request_failed', utils.jsToVal(err));

View File

@@ -4,7 +4,7 @@
*/
import { ref, computed } from 'vue';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
type SaveData = {
gameVersion: number;
@@ -23,7 +23,7 @@ let prev = '';
export async function load() {
try {
saveData.value = await os.api('i/registry/get', {
saveData.value = await misskeyApi('i/registry/get', {
scope: ['clickerGame'],
key: 'saveData',
});
@@ -63,7 +63,7 @@ export async function save() {
const current = JSON.stringify(saveData.value);
if (current === prev) return;
await os.api('i/registry/set', {
await misskeyApi('i/registry/set', {
scope: ['clickerGame'],
key: 'saveData',
value: saveData.value,

View File

@@ -18,7 +18,7 @@ export async function genSearchQuery(v: any, q: string) {
host = at;
}
} else {
const user = await v.os.api('users/show', Misskey.acct.parse(at)).catch(x => null);
const user = await v.api('users/show', Misskey.acct.parse(at)).catch(x => null);
if (user) {
userId = user.id;
} else {

View File

@@ -8,6 +8,7 @@ import { defineAsyncComponent } from 'vue';
import { i18n } from '@/i18n.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { MenuItem } from '@/types/menu.js';
import { defaultStore } from '@/store.js';
@@ -18,7 +19,7 @@ function rename(file: Misskey.entities.DriveFile) {
default: file.name,
}).then(({ canceled, result: name }) => {
if (canceled) return;
os.api('drive/files/update', {
misskeyApi('drive/files/update', {
fileId: file.id,
name: name,
});
@@ -31,7 +32,7 @@ function describe(file: Misskey.entities.DriveFile) {
file: file,
}, {
done: caption => {
os.api('drive/files/update', {
misskeyApi('drive/files/update', {
fileId: file.id,
comment: caption.length === 0 ? null : caption,
});
@@ -40,7 +41,7 @@ function describe(file: Misskey.entities.DriveFile) {
}
function toggleSensitive(file: Misskey.entities.DriveFile) {
os.api('drive/files/update', {
misskeyApi('drive/files/update', {
fileId: file.id,
isSensitive: !file.isSensitive,
}).catch(err => {
@@ -69,7 +70,7 @@ async function deleteFile(file: Misskey.entities.DriveFile) {
});
if (canceled) return;
os.api('drive/files/delete', {
misskeyApi('drive/files/delete', {
fileId: file.id,
});
}

View File

@@ -10,6 +10,7 @@ import { $i } from '@/account.js';
import { i18n } from '@/i18n.js';
import { instance } from '@/instance.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { url } from '@/config.js';
import { defaultStore, noteActions } from '@/store.js';
@@ -40,7 +41,7 @@ export async function getNoteClipMenu(props: {
action: () => {
claimAchievement('noteClipped1');
os.promiseDialog(
os.api('clips/add-note', { clipId: clip.id, noteId: appearNote.id }),
misskeyApi('clips/add-note', { clipId: clip.id, noteId: appearNote.id }),
null,
async (err) => {
if (err.id === '734806c4-542c-463a-9311-15c512803965') {
@@ -145,7 +146,7 @@ export function getNoteMenu(props: {
}).then(({ canceled }) => {
if (canceled) return;
os.api('notes/delete', {
misskeyApi('notes/delete', {
noteId: appearNote.id,
});
@@ -162,7 +163,7 @@ export function getNoteMenu(props: {
}).then(({ canceled }) => {
if (canceled) return;
os.api('notes/delete', {
misskeyApi('notes/delete', {
noteId: appearNote.id,
});
@@ -243,7 +244,7 @@ export function getNoteMenu(props: {
async function translate(): Promise<void> {
if (props.translation.value != null) return;
props.translating.value = true;
const res = await os.api('notes/translate', {
const res = await misskeyApi('notes/translate', {
noteId: appearNote.id,
targetLang: miLocalStorage.getItem('lang') ?? navigator.language,
});
@@ -253,7 +254,7 @@ export function getNoteMenu(props: {
let menu: MenuItem[];
if ($i) {
const statePromise = os.api('notes/state', {
const statePromise = misskeyApi('notes/state', {
noteId: appearNote.id,
});
@@ -330,7 +331,7 @@ export function getNoteMenu(props: {
icon: 'ti ti-user',
text: i18n.ts.user,
children: async () => {
const user = appearNote.userId === $i?.id ? $i : await os.api('users/show', { userId: appearNote.userId });
const user = appearNote.userId === $i?.id ? $i : await misskeyApi('users/show', { userId: appearNote.userId });
const { menu, cleanup } = getUserMenu(user);
cleanups.push(cleanup);
return menu;
@@ -361,7 +362,7 @@ export function getNoteMenu(props: {
children: async () => {
const channelChildMenu = [] as MenuItem[];
const channel = await os.api('channels/show', { channelId: appearNote.channel!.id });
const channel = await misskeyApi('channels/show', { channelId: appearNote.channel!.id });
if (channel.pinnedNoteIds.includes(appearNote.id)) {
channelChildMenu.push({
@@ -425,7 +426,7 @@ export function getNoteMenu(props: {
}
if (noteActions.length > 0) {
menu = menu.concat([{ type: "divider" }, ...noteActions.map(action => ({
menu = menu.concat([{ type: 'divider' }, ...noteActions.map(action => ({
icon: 'ti ti-plug',
text: action.title,
action: () => {
@@ -435,7 +436,7 @@ export function getNoteMenu(props: {
}
if (defaultStore.state.devMode) {
menu = menu.concat([{ type: "divider" }, {
menu = menu.concat([{ type: 'divider' }, {
icon: 'ti ti-id',
text: i18n.ts.copyNoteId,
action: () => {
@@ -499,7 +500,7 @@ export function getRenoteMenu(props: {
}
if (!props.mock) {
os.api('notes/create', {
misskeyApi('notes/create', {
renoteId: appearNote.id,
channelId: appearNote.channelId,
}).then(() => {
@@ -544,7 +545,7 @@ export function getRenoteMenu(props: {
}
if (!props.mock) {
os.api('notes/create', {
misskeyApi('notes/create', {
localOnly,
visibility,
renoteId: appearNote.id,

View File

@@ -10,6 +10,7 @@ import { i18n } from '@/i18n.js';
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
import { host, url } from '@/config.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { defaultStore, userActions } from '@/store.js';
import { $i, iAmModerator } from '@/account.js';
import { mainRouter } from '@/router.js';
@@ -131,7 +132,7 @@ export function getUserMenu(user: Misskey.entities.UserDetailed, router: Router
}
async function editMemo(): Promise<void> {
const userDetailed = await os.api('users/show', {
const userDetailed = await misskeyApi('users/show', {
userId: user.id,
});
const { canceled, result } = await os.form(i18n.ts.editMemo, {

View File

@@ -10,6 +10,7 @@ import { Interpreter, Parser, utils } from '@syuilo/aiscript';
import type { Plugin } from '@/store.js';
import { ColdDeviceStorage } from '@/store.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js';
export type AiScriptPluginMeta = {
@@ -110,7 +111,7 @@ export async function installPlugin(code: string, meta?: AiScriptPluginMeta) {
}, {
done: async result => {
const { name, permissions } = result;
const { token } = await os.api('miauth/gen-token', {
const { token } = await misskeyApi('miauth/gen-token', {
session: null,
name: name,
permission: permissions,

View File

@@ -6,6 +6,7 @@
import * as Misskey from 'misskey-js';
import { i18n } from '@/i18n.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
export async function lookupUser() {
const { canceled, result } = await os.inputText({
@@ -17,8 +18,8 @@ export async function lookupUser() {
os.pageWindow(`/admin/user/${user.id}`);
};
const usernamePromise = os.api('users/show', Misskey.acct.parse(result));
const idPromise = os.api('users/show', { userId: result });
const usernamePromise = misskeyApi('users/show', Misskey.acct.parse(result));
const idPromise = misskeyApi('users/show', { userId: result });
let _notFound = false;
const notFound = () => {
if (_notFound) {

View File

@@ -4,6 +4,7 @@
*/
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { i18n } from '@/i18n.js';
import { mainRouter } from '@/router.js';
import { Router } from '@/nirax.js';
@@ -28,7 +29,7 @@ export async function lookup(router?: Router) {
}
if (query.startsWith('https://')) {
const promise = os.api('ap/show', {
const promise = misskeyApi('ap/show', {
uri: query,
});

View File

@@ -10,7 +10,7 @@ import { $i } from '@/account.js';
export const pendingApiRequestsCount = ref(0);
// Implements Misskey.api.ApiClient.request
export function api<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(
export function misskeyApi<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(
endpoint: E,
data: P = {} as any,
token?: string | null | undefined,
@@ -57,7 +57,7 @@ export function api<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoin
}
// Implements Misskey.api.ApiClient.request
export function apiGet<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(
export function misskeyApiGet<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(
endpoint: E,
data: P = {} as any,
): Promise<Misskey.api.SwitchCaseResponseType<E, P>> {

View File

@@ -6,6 +6,7 @@
import { ref } from 'vue';
import * as Misskey from 'misskey-js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { useStream } from '@/stream.js';
import { i18n } from '@/i18n.js';
import { defaultStore } from '@/store.js';
@@ -65,7 +66,7 @@ export function chooseFileFromUrl(): Promise<Misskey.entities.DriveFile> {
}
});
os.api('drive/files/upload-from-url', {
misskeyApi('drive/files/upload-from-url', {
url: url,
folderId: defaultStore.state.uploadFolder,
marker,

View File

@@ -5,7 +5,7 @@
import type { SoundStore } from '@/store.js';
import { defaultStore } from '@/store.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
let ctx: AudioContext;
const cache = new Map<string, AudioBuffer>();
@@ -120,7 +120,7 @@ export async function loadAudio(soundStore: SoundStore, options?: { useCache?: b
} catch (err) {
try {
// URLが変わっている可能性があるのでドライブ側からURLを取得するフォールバック
const apiRes = await os.api('drive/files/show', {
const apiRes = await misskeyApi('drive/files/show', {
fileId: soundStore.fileId,
});
response = await fetch(apiRes.url);