76 lines
2.0 KiB
TypeScript
76 lines
2.0 KiB
TypeScript
|
export namespace controller {
|
||
|
|
||
|
export class FileInfo {
|
||
|
filename?: string;
|
||
|
prefix?: string;
|
||
|
created_at?: string;
|
||
|
size?: number;
|
||
|
is_dir?: boolean;
|
||
|
|
||
|
static createFrom(source: any = {}) {
|
||
|
return new FileInfo(source);
|
||
|
}
|
||
|
|
||
|
constructor(source: any = {}) {
|
||
|
if ('string' === typeof source) source = JSON.parse(source);
|
||
|
this.filename = source["filename"];
|
||
|
this.prefix = source["prefix"];
|
||
|
this.created_at = source["created_at"];
|
||
|
this.size = source["size"];
|
||
|
this.is_dir = source["is_dir"];
|
||
|
}
|
||
|
}
|
||
|
export class UpyunConfig {
|
||
|
bucket: string;
|
||
|
operator: string;
|
||
|
password: string;
|
||
|
domain: string;
|
||
|
|
||
|
static createFrom(source: any = {}) {
|
||
|
return new UpyunConfig(source);
|
||
|
}
|
||
|
|
||
|
constructor(source: any = {}) {
|
||
|
if ('string' === typeof source) source = JSON.parse(source);
|
||
|
this.bucket = source["bucket"];
|
||
|
this.operator = source["operator"];
|
||
|
this.password = source["password"];
|
||
|
this.domain = source["domain"];
|
||
|
}
|
||
|
}
|
||
|
export class ServerConfig {
|
||
|
environment: string;
|
||
|
upyun: UpyunConfig;
|
||
|
|
||
|
static createFrom(source: any = {}) {
|
||
|
return new ServerConfig(source);
|
||
|
}
|
||
|
|
||
|
constructor(source: any = {}) {
|
||
|
if ('string' === typeof source) source = JSON.parse(source);
|
||
|
this.environment = source["environment"];
|
||
|
this.upyun = this.convertValues(source["upyun"], UpyunConfig);
|
||
|
}
|
||
|
|
||
|
convertValues(a: any, classs: any, asMap: boolean = false): any {
|
||
|
if (!a) {
|
||
|
return a;
|
||
|
}
|
||
|
if (a.slice) {
|
||
|
return (a as any[]).map(elem => this.convertValues(elem, classs));
|
||
|
} else if ("object" === typeof a) {
|
||
|
if (asMap) {
|
||
|
for (const key of Object.keys(a)) {
|
||
|
a[key] = new classs(a[key]);
|
||
|
}
|
||
|
return a;
|
||
|
}
|
||
|
return new classs(a);
|
||
|
}
|
||
|
return a;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|