feat: Serve static assets of apps
This commit is contained in:
@@ -4,22 +4,28 @@ class App {
|
||||
static folderPath = __dirname + '/../apps';
|
||||
static list = fs.readdirSync(this.folderPath);
|
||||
|
||||
static findAll(name?: string): object[] {
|
||||
if(!name) return this.list.map((name) => this.findOneByName(name));
|
||||
static async findAll(name?: string): Promise<object[]> {
|
||||
let appList;
|
||||
|
||||
return this.list
|
||||
.filter((app) => app.includes(name.toLowerCase()))
|
||||
.map((name) => this.findOneByName(name));
|
||||
if(!name) {
|
||||
appList = this.list.map(async (name) => await this.findOneByName(name));
|
||||
} else {
|
||||
appList = this.list
|
||||
.filter((app) => app.includes(name.toLowerCase()))
|
||||
.map(async (name) => await this.findOneByName(name));
|
||||
}
|
||||
|
||||
return Promise.all(appList)
|
||||
}
|
||||
|
||||
static findOneByName(name: string): object {
|
||||
const rawAppData = fs.readFileSync(this.folderPath + `/${name}/info.json`, 'utf-8');
|
||||
return JSON.parse(rawAppData);
|
||||
static async findOneByName(name: string): Promise<object> {
|
||||
const rawAppData = (await import(`../apps/${name}/info`)).default;
|
||||
return rawAppData;
|
||||
}
|
||||
|
||||
static findOneByKey(key: string): object {
|
||||
const rawAppData = fs.readFileSync(this.folderPath + `/${key}/info.json`, 'utf-8');
|
||||
return JSON.parse(rawAppData);
|
||||
static async findOneByKey(key: string): Promise<object> {
|
||||
const rawAppData = (await import(`../apps/${key}/info`)).default;
|
||||
return rawAppData;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user