core: add avatar provider API

This commit is contained in:
undefined committed 2021-04-19 23:39:51 +08:00
1 parent 2db1570d1b
commit f1f956202f
42 files changed
+122 -80

No files matched your search

+22 -8
View File
@@ -265,14 +265,14 @@ export namespace Time {
export function errorMessage(err: Error | string) {
const t = typeof err === 'string' ? err : err.stack;
const q = t.split('\n');
for (let i = 0; i < q.length; i++) {
if (!q[i].startsWith(' at')) continue;
if (q[i].includes(`${sep}@hydrooj${sep}`)) q[i] = q[i].split(`@hydrooj${sep}`)[1];
else if (q[i].includes(`${sep}hydrooj${sep}`)) q[i] = ` at hydrooj${sep}${q[i].split(`hydrooj${sep}`)[1]}`;
}
if (typeof err === 'string') return q.join('\n');
err.stack = q.join('\n');
const parsed = t
.replace(/[A-Z]:\\.+\\@hydrooj\\/g, '\\')
.replace(/\/.+\/@hydrooj\//g, '\\')
.replace(/[A-Z]:\\.+\\hydrooj\\/g, 'hydrooj\\')
.replace(/\/.+\/hydrooj\//g, 'hydrooj/')
.replace(/\\/g, '/');
if (typeof err === 'string') return parsed;
err.stack = parsed;
return err;
}
@@ -376,3 +376,17 @@ export async function retry(arg0: number | Function, func: any, ...args: any[])
return res;
}
}
export function CallableInstance(property = '__call__') {
let func;
if (typeof property === 'function') func = property;
else func = this.constructor.prototype[property];
const apply = function __call__(...args) { return func.apply(apply, ...args); };
Object.setPrototypeOf(apply, this.constructor.prototype);
Object.getOwnPropertyNames(func).forEach((p) => {
Object.defineProperty(apply, p, Object.getOwnPropertyDescriptor(func, p));
});
return apply;
}
CallableInstance.prototype = Object.create(Function.prototype);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/utils",
"version": "1.0.5",
"version": "1.0.6",
"description": "hydrooj utils",
"main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git",