MCPcopy
hub / github.com/marktext/marktext / DataCenter

Class DataCenter

packages/desktop/src/main/dataCenter/index.ts:23–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21}
22
23class DataCenter extends TypedEmitter<DataCenterEvents> {
24 dataCenterPath: string
25 userDataPath: string
26 serviceName: string
27 encryptKeys: string[]
28 hasDataCenterFile: boolean
29 // eslint-disable-next-line @typescript-eslint/no-explicit-any
30 store: Store<any>
31
32 constructor(paths: DataCenterPaths) {
33 super()
34
35 const { dataCenterPath, userDataPath } = paths
36 this.dataCenterPath = dataCenterPath
37 this.userDataPath = userDataPath
38 this.serviceName = 'marktext'
39 this.encryptKeys = []
40 this.hasDataCenterFile = fs.existsSync(
41 path.join(this.dataCenterPath, `./${DATA_CENTER_NAME}.json`)
42 )
43 // eslint-disable-next-line @typescript-eslint/no-explicit-any
44 this.store = new Store<any>({
45 // eslint-disable-next-line @typescript-eslint/no-explicit-any
46 schema: schema as any,
47 name: DATA_CENTER_NAME
48 })
49
50 this.init()
51 }
52
53 init(): void {
54 const defaultData = {
55 imageFolderPath: path.join(this.userDataPath, 'images'),
56 screenshotFolderPath: path.join(this.userDataPath, 'screenshot'),
57 webImages: [],
58 cloudImages: [],
59 currentUploader: 'picgo'
60 }
61
62 if (!this.hasDataCenterFile) {
63 this.store.set(defaultData)
64 ensureDirSync(this.store.get('screenshotFolderPath') as string)
65 } else {
66 // Migrate legacy uploader values that no longer exist
67 const stored = this.store.get('currentUploader') as string | undefined
68 if (stored === 'none' || stored === 'github') {
69 this.store.set('currentUploader', 'picgo')
70 }
71 }
72 this._listenForIpcMain()
73 }
74
75 // eslint-disable-next-line @typescript-eslint/no-explicit-any
76 async getAll(): Promise<Record<string, any>> {
77 const { serviceName, encryptKeys } = this
78 const data = this.store.store
79 try {
80 const encryptData = await Promise.all(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected