move plugin move to account.
This commit is contained in:
parent
dd54ec4186
commit
44e3d2907a
|
@ -1167,6 +1167,9 @@ export interface Locale {
|
|||
"overrideSourceCodeOnly": string;
|
||||
"syncSetting": string;
|
||||
"syncing": string;
|
||||
"movePluginToAccount": string;
|
||||
"movePluginToAccountConfirm": string;
|
||||
"overridePluginConfirm": string;
|
||||
"_announcement": {
|
||||
"forExistingUsers": string;
|
||||
"forExistingUsersDescription": string;
|
||||
|
|
|
@ -1164,6 +1164,9 @@ duplicateSyncedPlugin: "このプラグインは同期されているプラグ
|
|||
overrideSourceCodeOnly: "コードのみを上書きする"
|
||||
syncSetting: "同期設定"
|
||||
syncing: "他端末と同期"
|
||||
movePluginToAccount: "アカウントに移行"
|
||||
movePluginToAccountConfirm: "プラグインをアカウントに移行して他端末と同期しますか?プラグインとプラグイン設定以外は引き継がれません。"
|
||||
overridePluginConfirm: "すでにプラグインがアカウントに存在します。上書きしますか?アカウントにあるプラグインデータは削除されます。"
|
||||
|
||||
_announcement:
|
||||
forExistingUsers: "既存ユーザーのみ"
|
||||
|
|
|
@ -38,6 +38,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||
|
||||
<div class="_buttons">
|
||||
<MkButton v-if="plugin.config" inline @click="config(plugin)"><i class="ti ti-settings"></i> {{ i18n.ts.settings }}</MkButton>
|
||||
<MkButton v-if="!plugin.fromAccount" inline @click="moveToAccount(plugin)"><i class="ti ti-link"></i> {{ i18n.ts.movePluginToAccount }}</MkButton>
|
||||
<MkButton inline danger @click="uninstall(plugin)"><i class="ti ti-trash"></i> {{ i18n.ts.uninstall }}</MkButton>
|
||||
</div>
|
||||
|
||||
|
@ -75,6 +76,8 @@ import { unisonReload } from '@/scripts/unison-reload.js';
|
|||
import { i18n } from '@/i18n.js';
|
||||
import { definePageMetadata } from '@/scripts/page-metadata.js';
|
||||
import { getPluginList } from '@/plugin.js';
|
||||
import { toHash } from '@/scripts/xxhash.js';
|
||||
import { savePluginToAccount } from '@/scripts/install-plugin.js';
|
||||
|
||||
let plugins = Object.values(await getPluginList());
|
||||
plugins.push(...ColdDeviceStorage.get('plugins'));
|
||||
|
@ -87,7 +90,8 @@ async function uninstall(plugin) {
|
|||
await os.api('i/registry/remove-all-keys-in-scope', { scope: ['client', 'aiscript', 'plugins', plugin.id] });
|
||||
await os.api('i/registry/set', { scope: ['client'], key: 'plugins', value: plugins });
|
||||
} else {
|
||||
ColdDeviceStorage.set('plugins', plugins.value.filter(x => x.id !== plugin.id));
|
||||
const coldPlugins = ColdDeviceStorage.get('plugins');
|
||||
ColdDeviceStorage.set('plugins', coldPlugins.filter(x => x.id !== plugin.id));
|
||||
}
|
||||
await os.apiWithDialog('i/revoke-token', {
|
||||
token: plugin.token,
|
||||
|
@ -97,6 +101,37 @@ async function uninstall(plugin) {
|
|||
});
|
||||
}
|
||||
|
||||
async function moveToAccount(plugin) {
|
||||
const { canceled } = await os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.ts.movePluginToAccountConfirm,
|
||||
});
|
||||
|
||||
if (canceled) return;
|
||||
|
||||
const hash = await toHash(plugin.name, plugin.author);
|
||||
const plugins = await getPluginList();
|
||||
if (Object.keys(plugins).some(v => v === hash)) {
|
||||
const { canceled } = await os.confirm({
|
||||
type: 'warning',
|
||||
text: i18n.ts.overridePluginConfirm,
|
||||
});
|
||||
|
||||
if (canceled) return;
|
||||
|
||||
await os.api('i/registry/remove-all-keys-in-scope', { scope: ['client', 'aiscript', 'plugins', hash] });
|
||||
}
|
||||
|
||||
const coldPlugins = ColdDeviceStorage.get('plugins');
|
||||
ColdDeviceStorage.set('plugins', coldPlugins.filter(x => x.id !== plugin.id));
|
||||
|
||||
plugin.id = hash;
|
||||
plugin.fromAccount = true;
|
||||
plugins[hash] = plugin;
|
||||
|
||||
await os.api('i/registry/set', { scope: ['client'], key: 'plugins', value: plugins });
|
||||
}
|
||||
|
||||
function copy(plugin) {
|
||||
copyToClipboard(plugin.src ?? '');
|
||||
os.success();
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
import { defineAsyncComponent } from 'vue';
|
||||
import { compareVersions } from 'compare-versions';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import xxhash from 'xxhash-wasm';
|
||||
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 { i18n } from '@/i18n.js';
|
||||
import { getPluginList } from '@/plugin.js';
|
||||
import { toHash } from './xxhash.js';
|
||||
|
||||
export type AiScriptPluginMeta = {
|
||||
name: string;
|
||||
|
@ -25,11 +25,6 @@ export type AiScriptPluginMeta = {
|
|||
|
||||
const parser = new Parser();
|
||||
|
||||
async function toHash(name: string, author: string) {
|
||||
const { h32ToString } = await xxhash();
|
||||
return h32ToString(author + name);
|
||||
}
|
||||
|
||||
export function savePlugin({ id, meta, src, token }: {
|
||||
id: string;
|
||||
meta: AiScriptPluginMeta;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
import xxhash from 'xxhash-wasm';
|
||||
|
||||
export async function toHash(name: string, author: string) {
|
||||
const { h32ToString } = await xxhash();
|
||||
return h32ToString(author + name);
|
||||
}
|
Loading…
Reference in New Issue