mirror of
https://github.com/MCSManager/MCSManager.git
synced 2024-11-27 06:59:54 +08:00
Feat: sync common code
This commit is contained in:
parent
adcb208c9f
commit
ecc77480dc
@ -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[]>();
|
||||
|
@ -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) {}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user