change name scriptData to storageMetadata
This commit is contained in:
parent
3f198b9ae2
commit
0bef3f2ce4
|
|
@ -145,7 +145,7 @@ async function run() {
|
|||
|
||||
aiscript = new Interpreter({
|
||||
...createAiScriptEnv({
|
||||
scriptData: {
|
||||
storageMetadata: {
|
||||
type: 'flash',
|
||||
id: flash.id,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ async function run() {
|
|||
aiscript = new Interpreter(({
|
||||
...createAiScriptEnv({
|
||||
token: $i?.token,
|
||||
scriptData: {
|
||||
storageMetadata: {
|
||||
type: 'widget',
|
||||
},
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ function createPluginEnv(opts: { plugin: Plugin; }): Record<string, values.Value
|
|||
}
|
||||
|
||||
return {
|
||||
...createAiScriptEnv({ token: opts.plugin.token, scriptData: { type: 'plugins', id: opts.plugin.id, fromAccount: opts.plugin.fromAccount } }),
|
||||
...createAiScriptEnv({ token: opts.plugin.token, storageMetadata: { type: 'plugins', id: opts.plugin.id, fromAccount: opts.plugin.fromAccount } }),
|
||||
//#region Deprecated
|
||||
'Mk:register_post_form_action': values.FN_NATIVE(([title, handler]) => {
|
||||
utils.assertString(title);
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ import { $i } from '@/account.js';
|
|||
import { customEmojis } from '@/custom-emojis.js';
|
||||
import { url, lang } from '@/config.js';
|
||||
import { nyaize } from '@/scripts/nyaize.js';
|
||||
import { ScriptData, loadScriptStorage, saveScriptStorage } from './storage.js';
|
||||
import { StorageMetadata, loadScriptStorage, saveScriptStorage } from './storage.js';
|
||||
|
||||
export function createAiScriptEnv(opts: { token: string; scriptData: ScriptData; }) {
|
||||
export function createAiScriptEnv(opts: { token: string; storageMetadata: StorageMetadata; }) {
|
||||
return {
|
||||
USER_ID: $i ? values.STR($i.id) : values.NULL,
|
||||
USER_NAME: $i ? values.STR($i.name) : values.NULL,
|
||||
|
|
@ -69,7 +69,7 @@ export function createAiScriptEnv(opts: { token: string; scriptData: ScriptData;
|
|||
}
|
||||
}
|
||||
const saveToAccount = option && option.value.toAccount ? option.value.toAccount.value : false;
|
||||
return saveScriptStorage(saveToAccount, opts.scriptData, key.value, utils.valToJs(value)).then(() => {
|
||||
return saveScriptStorage(saveToAccount, opts.storageMetadata, key.value, utils.valToJs(value)).then(() => {
|
||||
return values.NULL;
|
||||
}, err => {
|
||||
return values.ERROR('request_failed', utils.jsToVal(err));
|
||||
|
|
@ -84,7 +84,7 @@ export function createAiScriptEnv(opts: { token: string; scriptData: ScriptData;
|
|||
}
|
||||
}
|
||||
const loadToAccount = option && option.value.toAccount ? option.value.toAccount.value : false;
|
||||
return loadScriptStorage(loadToAccount, opts.scriptData, key.value).then(res => {
|
||||
return loadScriptStorage(loadToAccount, opts.storageMetadata, key.value).then(res => {
|
||||
return utils.jsToVal(res);
|
||||
}, err => {
|
||||
return values.ERROR('request_failed', utils.jsToVal(err));
|
||||
|
|
|
|||
|
|
@ -3,21 +3,21 @@ import { miLocalStorage } from '@/local-storage.js';
|
|||
import { $i } from '@/account.js';
|
||||
|
||||
type ScriptType = 'widget' | 'plugins' | 'flash';
|
||||
export type ScriptData = { type: ScriptType; id?: string; fromAccount?: boolean };
|
||||
export type StorageMetadata = { type: ScriptType; id?: string; fromAccount?: boolean };
|
||||
|
||||
export async function loadScriptStorage(toAccount: boolean, scriptData: ScriptData, key: string) {
|
||||
export async function loadScriptStorage(toAccount: boolean, storageMetadata: StorageMetadata, key: string) {
|
||||
let value: string | null;
|
||||
if ($i && toAccount && (scriptData.type !== 'plugins' || (scriptData.type === 'plugins' && scriptData.fromAccount))) {
|
||||
if (scriptData.type === 'widget') {
|
||||
value = await api('i/registry/get', { scope: ['client', 'aiscript', scriptData.type], key: key });
|
||||
if ($i && toAccount && (storageMetadata.type !== 'plugins' || (storageMetadata.type === 'plugins' && storageMetadata.fromAccount))) {
|
||||
if (storageMetadata.type === 'widget') {
|
||||
value = await api('i/registry/get', { scope: ['client', 'aiscript', storageMetadata.type], key: key });
|
||||
} else {
|
||||
value = await api('i/registry/get', { scope: ['client', 'aiscript', scriptData.type, scriptData.id!], key: key });
|
||||
value = await api('i/registry/get', { scope: ['client', 'aiscript', storageMetadata.type, storageMetadata.id!], key: key });
|
||||
}
|
||||
} else {
|
||||
if (scriptData.type === 'widget') {
|
||||
value = miLocalStorage.getItem(`aiscript:${scriptData.type}:${key}`);
|
||||
if (storageMetadata.type === 'widget') {
|
||||
value = miLocalStorage.getItem(`aiscript:${storageMetadata.type}:${key}`);
|
||||
} else {
|
||||
value = miLocalStorage.getItem(`aiscript:${scriptData.type}:${scriptData.id!}:${key}`);
|
||||
value = miLocalStorage.getItem(`aiscript:${storageMetadata.type}:${storageMetadata.id!}:${key}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -25,19 +25,19 @@ export async function loadScriptStorage(toAccount: boolean, scriptData: ScriptDa
|
|||
return JSON.parse(value);
|
||||
}
|
||||
|
||||
export async function saveScriptStorage(toAccount: boolean, scriptData: ScriptData, key: string, value: any) {
|
||||
export async function saveScriptStorage(toAccount: boolean, storageMetadata: StorageMetadata, key: string, value: any) {
|
||||
const jsonValue = JSON.stringify(value);
|
||||
if ($i && toAccount && (scriptData.type !== 'plugins' || (scriptData.type === 'plugins' && scriptData.fromAccount))) {
|
||||
if (scriptData.type === 'widget') {
|
||||
await api('i/registry/set', { scope: ['client', 'aiscript', scriptData.type], key: key, value: jsonValue });
|
||||
if ($i && toAccount && (storageMetadata.type !== 'plugins' || (storageMetadata.type === 'plugins' && storageMetadata.fromAccount))) {
|
||||
if (storageMetadata.type === 'widget') {
|
||||
await api('i/registry/set', { scope: ['client', 'aiscript', storageMetadata.type], key: key, value: jsonValue });
|
||||
} else {
|
||||
await api('i/registry/set', { scope: ['client', 'aiscript', scriptData.type, scriptData.id!], key: key, value: jsonValue });
|
||||
await api('i/registry/set', { scope: ['client', 'aiscript', storageMetadata.type, storageMetadata.id!], key: key, value: jsonValue });
|
||||
}
|
||||
} else {
|
||||
if (scriptData.type === 'widget') {
|
||||
miLocalStorage.setItem(`aiscript:${scriptData.type}:${key}`, jsonValue);
|
||||
if (storageMetadata.type === 'widget') {
|
||||
miLocalStorage.setItem(`aiscript:${storageMetadata.type}:${key}`, jsonValue);
|
||||
} else {
|
||||
miLocalStorage.setItem(`aiscript:${scriptData.type}:${scriptData.id!}:${key}`, jsonValue);
|
||||
miLocalStorage.setItem(`aiscript:${storageMetadata.type}:${storageMetadata.id!}:${key}`, jsonValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ const run = async () => {
|
|||
logs.value = [];
|
||||
const aiscript = new Interpreter(createAiScriptEnv({
|
||||
token: $i?.token,
|
||||
scriptData: {
|
||||
storageMetadata: {
|
||||
type: 'widget',
|
||||
},
|
||||
}), {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ async function run() {
|
|||
const aiscript = new Interpreter({
|
||||
...createAiScriptEnv({
|
||||
token: $i?.token,
|
||||
scriptData: {
|
||||
storageMetadata: {
|
||||
type: 'widget',
|
||||
},
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ const parser = new Parser();
|
|||
const run = async () => {
|
||||
const aiscript = new Interpreter(createAiScriptEnv({
|
||||
token: $i?.token,
|
||||
scriptData: {
|
||||
storageMetadata: {
|
||||
type: 'widget',
|
||||
},
|
||||
}), {
|
||||
|
|
|
|||
Loading…
Reference in New Issue