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