Feat: sync common code

This commit is contained in:
unitwk 2023-11-15 20:04:52 +08:00
parent adcb208c9f
commit ecc77480dc
3 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import { Socket } from "socket.io";
// Application instance data stream forwarding adapter
export default class InstanceStreamListener {
// Instance uuid -> Socket[]
public readonly listenMap = new Map<string, Socket[]>();

View File

@ -11,7 +11,6 @@ interface Page<T> {
data: T[];
}
// This design can be used to connect to MYSQL, SQLITE and other databases
// Provide the MAP query interface used by the routing layer
export class QueryMapWrapper {
constructor(public map: IMap) {}

View File

@ -1,10 +1,6 @@
import path from "path";
import fs from "fs-extra";
interface IClassz {
name: string;
}
class StorageSubsystem {
public static readonly DATA_PATH = path.normalize(path.join(process.cwd(), "data"));
public static readonly INDEX_PATH = path.normalize(path.join(process.cwd(), "data", "index"));
@ -17,6 +13,26 @@ class StorageSubsystem {
return true;
}
public writeFile(name: string, data: string) {
const targetPath = path.normalize(path.join(StorageSubsystem.DATA_PATH, name));
fs.writeFileSync(targetPath, data, { encoding: "utf-8" });
}
public readFile(name: string) {
const targetPath = path.normalize(path.join(StorageSubsystem.DATA_PATH, name));
return fs.readFileSync(targetPath, { encoding: "utf-8" });
}
public deleteFile(name: string) {
const targetPath = path.normalize(path.join(StorageSubsystem.DATA_PATH, name));
fs.removeSync(targetPath);
}
public fileExists(name: string) {
const targetPath = path.normalize(path.join(StorageSubsystem.DATA_PATH, name));
return fs.existsSync(targetPath);
}
// Stored in local file based on class definition and identifier
public store(category: string, uuid: string, object: any) {
const dirPath = path.join(StorageSubsystem.DATA_PATH, category);