This commit is contained in:
Freddie Wang
2020-12-11 13:52:25 +08:00
parent 449ff392dc
commit b723085c8b
12 changed files with 142 additions and 61 deletions

View File

@@ -1,6 +1,13 @@
## v1.20
- **API**: Added `IO.Exists` for checking whether a file exists
- **API**: Added `U.NFC2Card` and `U.Card2NFC` for card number conversion
- **WebUI**: Removed "Game Support" section in plugins' overview if no game support is registered
- **WebUI**: Minor WebUI visual update
## v1.19
- **WebUI**: Query shell is now avaliable for all installed plugins even if there are no DB data of them
- **WebUI**: Query shell is now available for all installed plugins even if there are no DB data of them
- **WebUI**: Fixed a issue where the WebUI of plugins with uppercase letter cannot be accessed
- **WebUI**: Custom WebUI pages now works without `//DATA//` section.
- **API**: Fixed a typechecking issue where `{ exists: true }` query is only allowed on number/string fields
@@ -42,7 +49,7 @@
## v1.13 beta
- **PluginLoader**: Now a gamecode can not be registered by multiple plugins
- **Router**: Errors in plugins now print callstack
- **Router**: Errors in plugins now print stack
- **Typescript**: Updated to 3.9.3
- **Typescript**: Typescript will now skip type checking if CORE is not in Developer Mode
- **CORE**: Fixed a problem where kencoded-message parsing fails if the message contains arrays

File diff suppressed because one or more lines are too long

View File

@@ -358,3 +358,12 @@ a.tag.is-dark:hover {
#shell-content code {
overflow-x: hidden;
}
.no-bottom {
margin-bottom: 0 !important;
}
.menu-item-label.expandable {
width: 75%;
overflow-wrap: break-word;
}

View File

@@ -11,7 +11,7 @@ mixin li_plugin(icon, label, link, pages)
a.has-icon.has-dropdown-icon(class=(plugin == link) ? 'is-active' : '' href='/plugin/' + link)
span.icon
i.mdi(class='mdi-'+icon)
span.menu-item-label #{label}
span.menu-item-label.expandable #{label}
.dropdown-icon
span.icon.plus
i.mdi.mdi-plus

View File

@@ -42,7 +42,8 @@ mixin form_control(option)
label.switch.is-rounded
input(type='checkbox' name=option.key checked=option.current)
span.check
p.help #{option.desc}
if option.desc
p.help #{option.desc}
mixin form(name, options)
.card
@@ -66,7 +67,7 @@ mixin form(name, options)
button.button.is-link(type='submit') Apply
mixin file_control(option)
.field.is-horizontal
.field.is-horizontal.no-bottom
.field-label(class=(option.type != 'boolean') ? "is-normal" : "")
label.label(for=option.key) #{option.name}
.field-body
@@ -106,11 +107,15 @@ mixin file_control(option)
span.icon
i.mdi.mdi-upload
if option.uploaded
p.control
.control
button.data-delete.button.is-danger(deleting=option.path)
span.icon
i.mdi.mdi-trash-can
span Clear
.field.is-horizontal
.field-label
.field-body
if option.desc
p.help #{option.desc}
mixin files(name, options)

View File

@@ -34,16 +34,17 @@ block content
| Information
.card-content !{readme}
.column
.card
header.card-header
p.card-header-title
span.icon
i.mdi.mdi-gamepad-variant-outline
| Game Support
.card-content
span.tags
each code in gameCodes
span.tag.is-primary #{code}
if gameCodes && gameCodes.length > 0
.card
header.card-header
p.card-header-title
span.icon
i.mdi.mdi-gamepad-variant-outline
| Game Support
.card-content
span.tags
each code in gameCodes
span.tag.is-primary #{code}
if datafile.length
+files("Data Upload", datafile)
if config.length

2
docs

Submodule docs updated: 940921282b...06aadd6e05

View File

@@ -93,7 +93,7 @@ declare interface EamuseInfo {
* Details of a config
*/
declare interface ConfigOption {
/** Provide a name to display in webui. If not provided, webui will use key as the name. */
/** Provide a name to display in WebUI. If not provided, WebUI will use key as the name. */
name?: string;
/** Provide a description for the option */
desc?: string;
@@ -112,16 +112,20 @@ declare interface ConfigOption {
}
/**
* Details of a datafile
* Details of a data file
*/
declare interface FileOption {
/** Provide a name to display in webui. If not provided, webui will use filename as the label. */
/** Provide a name to display in WebUI. If not provided, WebUI will use filename as the label. */
name?: string;
/** Provide a description for the entry */
desc?: string;
/** The accept attribute of the file input element. See [[https://www.w3schools.com/tags/att_input_accept.asp]] */
accept?: string;
/** Whether the file required for the plugin to work, defaults to false */
/**
* Whether the file is required for the plugin to work, defaults to false.
*
* Note that this only provides visual hint for the file in WebUI.
*/
required?: boolean;
}
@@ -170,7 +174,7 @@ declare interface EamuseSend {
* When constructing objects, make sure to use helper [[K]]:
* ```
* {
* outter: K.ATTR({ status: "1" }, {
* outer: K.ATTR({ status: "1" }, {
* inner: K.ITEM("s32", 1)
* })
* }
@@ -179,7 +183,7 @@ declare interface EamuseSend {
* Or follow xml-like format manually:
* ```
* {
* outter: {
* outer: {
* "@attr": { status: "1" },
* inner: {
* "@attr": { __type: "s32" },
@@ -327,7 +331,7 @@ declare namespace R {
}
/**
* A warpper of javascript object for reading xml-like formatted data.
* A wrapper of javascript object for reading xml-like formatted data.
*/
declare class KDataReader {
/**
@@ -337,7 +341,7 @@ declare class KDataReader {
constructor(obj: any);
/**
* Get attrubutes for a tag
* Get attributes for a tag
*
* Example:
* ```xml
@@ -359,7 +363,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).attr("tag") // { status: "1" }
* $(data).element("tag").attr().status // "1"
@@ -389,7 +393,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).element("inner").bigint() // 1n
* $(data).bigint("inner.1") // 2n
@@ -419,7 +423,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).bigints("inner") // [1n, 2n]
* $(data).bigints("invalid") // undefined
@@ -446,7 +450,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).bool("inner.0") // false
* $(data).bool("inner.1") // true
@@ -473,7 +477,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).buffer("inner") // <Buffer 00 ff>
* $(data).buffer("invalid") // undefined
@@ -500,7 +504,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).content("number") // [1]
* $(data).content("array") // [1, 2, 3]
@@ -532,7 +536,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).element("inner") // <KDataReader>
* $(data).element("inner").obj // { id: [object] }
@@ -564,7 +568,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).elements("inner") // [<KDataReader>, <KDataReader>]
* $(data).elements("inner")[1].number("id") // 2
@@ -593,7 +597,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).element("inner").number() // 1
* $(data).number("inner.1") // 2
@@ -623,7 +627,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).bigints("invalid") // undefined
* $(data).bigints("inner") // [3, 4]
@@ -649,7 +653,7 @@ declare class KDataReader {
* }
* ```
*
* Evals:
* Eval:
* ```javascript
* $(data).str("inner") // "abc"
* $(data).str("invalid") // undefined
@@ -807,6 +811,14 @@ declare namespace IO {
*/
function Resolve(path: string): string;
/**
* Synchronously tests whether or not the given path exists by checking with the file system.
* @param path
* A path to a file or directory. If a URL is provided, it must use the file: protocol. URL support is experimental.
*/
function Exists(path: string): boolean;
/**
* Asynchronously read a directory.
* @param path A path to a directory.
@@ -844,11 +856,13 @@ declare namespace IO {
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param options An object that may contain an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*
* Returns null if any error occurs while reading a file
*/
function ReadFile(
path: string,
options: { encoding?: null; flag?: string } | undefined | null
): Promise<Buffer>;
): Promise<Buffer | null>;
/**
* Asynchronously reads the entire contents of a file.
@@ -856,11 +870,13 @@ declare namespace IO {
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*
* Returns null if any error occurs while reading a file
*/
function ReadFile(
path: string,
options: { encoding: string; flag?: string } | string
): Promise<string>;
): Promise<string | null>;
/**
* Asynchronously reads the entire contents of a file.
@@ -868,18 +884,22 @@ declare namespace IO {
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
* @param options Either the encoding for the result, or an object that contains the encoding and an optional flag.
* If a flag is not provided, it defaults to `'r'`.
*
* Returns null if any error occurs while reading a file
*/
function ReadFile(
path: string,
options: { encoding?: string | null; flag?: string } | string | undefined | null
): Promise<string | Buffer>;
): Promise<string | Buffer | null>;
/**
* Asynchronously reads the entire contents of a file.
* @param path A path to a file.
* If a file descriptor is provided, the underlying file will _not_ be closed automatically.
*
* Returns null if any error occurs while reading a file.
*/
function ReadFile(path: string): Promise<Buffer>;
function ReadFile(path: string): Promise<Buffer | null>;
}
/**
@@ -908,6 +928,22 @@ declare namespace U {
* @param key
*/
function GetConfig(key: string): any;
/**
* Convert Card Number / Data Transfer Number to NFC serial
*
* returns null if the card number is invalid
* @param card Card Number / Data Transfer Number
*/
function Card2NFC(card: string): string | null;
/**
* Convert NFC serial to Card Number or Data Transfer Number
*
* returns null if the nfc serial is invalid
* @param card Card Number or Data Transfer Number
*/
function NFC2Card(nfc: string): string | null;
}
/** @ignore */
@@ -1011,7 +1047,7 @@ type Update<T> = Partial<T> & {
* ---
*
* **NOTE**: since WebUI can delete data in __ProfileSpace__,
* you should refrain from referencing refid in your document to prevent getting unclearable garbage data.
* you should refrain from referencing refid in your document to prevent getting residual garbage data.
*
* If you need to make rival/friend feature, we recommend you to get all profile data by passing null to `refid`.
* There will be 16 profiles maximum which is small enough to manage.

View File

@@ -28,6 +28,7 @@ import {
APIUpdate,
APIUpsert,
APICount,
Exists,
} from '../utils/EamuseIO';
import { readdirSync, existsSync } from 'fs';
import {
@@ -44,6 +45,7 @@ import xml2json from 'fast-xml-parser';
import _ from 'lodash';
import { isPlainObject } from 'lodash';
import { VERSION } from '../utils/Consts';
import { card2nfc, nfc2card } from '../utils/CardCipher';
/** Caller Detection */
export function GetCallerPlugin(): string {
@@ -69,11 +71,11 @@ export function GetCallerPlugin(): string {
return null;
}
const WrapCall = (name: string, func: any, def: any) => {
const WrapCall = (methodName: string, func: any, def: any) => {
return (...args: any) => {
const plugin = GetCallerPlugin();
if (!plugin) {
Logger.error(`${name} unexpected error`);
Logger.error(`${methodName} unexpected error`);
return def;
}
return func({ name: plugin, core: false }, ...args);
@@ -135,6 +137,7 @@ export function LoadExternalPlugins() {
WriteFile: WrapCall('IO.WriteFile', WriteFile, Pro(void 0)),
ReadFile: WrapCall('IO.ReadFile', ReadFile, Pro(null)),
ReadDir: WrapCall('IO.ReadDir', ReadDir, Pro([])),
Exists: WrapCall('IO.Exists', Exists, false),
};
$.DB = {
@@ -163,6 +166,20 @@ export function LoadExternalPlugins() {
if (!CONFIG[plugin]) return undefined;
return CONFIG[plugin][key];
},
NFC2Card: (nfc: string) => {
try {
return nfc2card(nfc);
} catch {
return null;
}
},
Card2NFC: (card: string) => {
try {
return card2nfc(card);
} catch {
return null;
}
}
};
$.R = {

View File

@@ -1,4 +1,4 @@
export const VERSION = 'v1.19';
export const VERSION = 'v1.20';
export const NAMES = [
'Akehiro',
'Akihiro',

View File

@@ -128,6 +128,11 @@ export async function ReadDir(plugin: PluginDetect, file: string) {
});
}
export function Exists(plugin: PluginDetect, file: string) {
const target = path.resolve(PLUGIN_PATH, plugin.name, file);
return existsSync(target);
}
export async function WriteFile(
plugin: PluginDetect,
file: string,
@@ -337,11 +342,11 @@ export async function FindCardsByRefid(refid: string) {
});
}
export async function CreateCard(cid: string, refid: string, forceprint?: string) {
export async function CreateCard(cid: string, refid: string, forcePrint?: string) {
let print = '<Invalid Card>';
if (forceprint) {
print = forceprint;
if (forcePrint) {
print = forcePrint;
} else {
try {
print = nfc2card(cid);
@@ -629,36 +634,36 @@ export async function APIInsert(plugin: PluginDetect, arg1: string | any, arg2?:
export async function APIUpdate(plugin: PluginDetect, arg1: string | any, arg2: any, arg3?: any) {
let query: any = null;
let update: any = null;
let signiture: any = { __a: plugin.name };
let signature: any = { __a: plugin.name };
if (typeof arg1 == 'string' && typeof arg2 == 'object' && typeof arg3 == 'object') {
arg2 = CheckQuery(arg2);
arg3 = CheckQuery(arg3);
query = arg2;
update = arg3;
signiture.__s = 'plugins_profile';
signiture.__refid = arg1;
signature.__s = 'plugins_profile';
signature.__refid = arg1;
} else if (arg1 == null && typeof arg2 == 'object' && typeof arg3 == 'object') {
arg2 = CheckQuery(arg2);
arg3 = CheckQuery(arg3);
query = arg2;
update = arg3;
signiture.__s = 'plugins_profile';
signature.__s = 'plugins_profile';
} else if (typeof arg1 == 'object' && typeof arg2 == 'object') {
arg1 = CheckQuery(arg1);
arg2 = CheckQuery(arg2);
query = arg1;
update = arg2;
signiture.__s = 'plugins';
signature.__s = 'plugins';
} else {
throw new Error('invalid Update query');
}
query = { ...query, ...signiture };
query = { ...query, ...signature };
if (!get(Object.keys(update), '0', '').startsWith('$')) {
update = {
...update,
...signiture,
...signature,
};
}
@@ -684,7 +689,7 @@ export async function APIUpdate(plugin: PluginDetect, arg1: string | any, arg2:
export async function APIUpsert(plugin: PluginDetect, arg1: string | any, arg2: any, arg3?: any) {
let query: any = null;
let update: any = null;
let signiture: any = { __a: plugin.name };
let signature: any = { __a: plugin.name };
if (typeof arg1 == 'string' && typeof arg2 == 'object' && typeof arg3 == 'object') {
arg2 = CheckQuery(arg2);
arg3 = CheckQuery(arg3);
@@ -697,8 +702,8 @@ export async function APIUpsert(plugin: PluginDetect, arg1: string | any, arg2:
}
query = arg2;
update = arg3;
signiture.__s = 'plugins_profile';
signiture.__refid = arg1;
signature.__s = 'plugins_profile';
signature.__refid = arg1;
} else if (arg1 == null && typeof arg2 == 'object' && typeof arg3 == 'object') {
throw new Error('refid must be specified for Upsert Query');
} else if (typeof arg1 == 'object' && typeof arg2 == 'object') {
@@ -706,17 +711,17 @@ export async function APIUpsert(plugin: PluginDetect, arg1: string | any, arg2:
arg2 = CheckQuery(arg2);
query = arg1;
update = arg2;
signiture.__s = 'plugins';
signature.__s = 'plugins';
} else {
throw new Error('invalid Upsert query');
}
query = { ...query, ...signiture };
query = { ...query, ...signature };
if (!get(Object.keys(update), '0', '').startsWith('$')) {
update = {
...update,
...signiture,
...signature,
};
}
return new Promise<any>((resolve, reject) => {

View File

@@ -100,6 +100,7 @@ function data(req: Request, title: string, plugin: string, attr?: any) {
return {
name: p.Name,
id: p.Identifier,
webOnly: p.GameCodes.length == 0,
pages: p.Pages.map(f => ({ name: startCase(f), link: f })),
};
}),