cleanup path management
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import ChatModel, { ChatMessage } from "./chatModel";
|
||||
import StorageModel, { filePaths } from "../Global/storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
|
||||
import ConnectionModel from "../Global/connectionModel";
|
||||
import { Message } from "udn-frontend";
|
||||
@@ -77,7 +77,7 @@ export default class ChatListModel {
|
||||
|
||||
// load
|
||||
loadChats = (): void => {
|
||||
const chatDir = StorageModel.getPath("chat", filePaths.chat.base);
|
||||
const chatDir = StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.base);
|
||||
const chatIds = this.storageModel.list(chatDir);
|
||||
for (const chatId of chatIds) {
|
||||
const chatModel = new ChatModel(
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
import StorageModel, { filePaths } from "../Global/storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
import { decryptString, encryptString } from "../Utility/crypto";
|
||||
|
||||
import ChatListModel from "./chatListModel";
|
||||
@@ -39,19 +39,19 @@ export default class ChatModel {
|
||||
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.chatBase(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.chatBase(this.id));
|
||||
};
|
||||
|
||||
getInfoPath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.info(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.info(this.id));
|
||||
};
|
||||
|
||||
getColorPath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.color(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.color(this.id));
|
||||
};
|
||||
|
||||
getMessageDirPath = (): string[] => {
|
||||
return StorageModel.getPath("chat", filePaths.chat.messages(this.id));
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.messages(this.id));
|
||||
};
|
||||
|
||||
getMessagePath = (id: string): string[] => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
import StorageModel, { filePaths } from "../Global/storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
|
||||
import BoardsAndTasksModel from "./boardsAndTasksModel";
|
||||
import ChatModel from "../Chat/chatModel";
|
||||
@@ -25,7 +25,7 @@ export default class FileModel {
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"chat",
|
||||
StorageModelSubPath.Chat,
|
||||
filePaths.chat.files(this.chatModel.id)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { ChatMessage, ChatMessageReference } from "../Chat/chatModel";
|
||||
import { Handler, HandlerManager, stringify } from "../Utility/utility";
|
||||
import StorageModel, { filePaths } from "./storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "./storageModel";
|
||||
import UDNFrontend, { Message } from "udn-frontend";
|
||||
|
||||
export default class ConnectionModel {
|
||||
@@ -34,7 +34,7 @@ export default class ConnectionModel {
|
||||
this.connectionChangeHandlerManager.trigger();
|
||||
|
||||
if (this.isConnected == false) return;
|
||||
if (!this.address) return;
|
||||
if (this.address == undefined) return;
|
||||
|
||||
this.connectMailbox();
|
||||
this.storeAddress(this.address);
|
||||
@@ -52,7 +52,7 @@ export default class ConnectionModel {
|
||||
|
||||
// do not reconnect
|
||||
const reconnectAddressPath: string[] = StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.reconnectAddress
|
||||
);
|
||||
this.storageModel.remove(reconnectAddressPath);
|
||||
@@ -61,7 +61,7 @@ export default class ConnectionModel {
|
||||
// mailbox
|
||||
getMailboxPath = (address: string): string[] => {
|
||||
const mailboxDirPath = StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.mailboxes
|
||||
);
|
||||
const mailboxFilePath = [...mailboxDirPath, address];
|
||||
@@ -69,7 +69,7 @@ export default class ConnectionModel {
|
||||
};
|
||||
|
||||
requestNewMailbox = (): void => {
|
||||
console.log("requesting mailbox");
|
||||
console.log("requesting new mailbox");
|
||||
this.udn.requestMailbox();
|
||||
};
|
||||
|
||||
@@ -107,7 +107,7 @@ export default class ConnectionModel {
|
||||
// outbox
|
||||
getOutboxPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.outbox
|
||||
);
|
||||
};
|
||||
@@ -173,7 +173,7 @@ export default class ConnectionModel {
|
||||
// storage
|
||||
getPreviousAddressPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.previousAddresses
|
||||
);
|
||||
};
|
||||
@@ -185,7 +185,7 @@ export default class ConnectionModel {
|
||||
|
||||
getReconnectAddressPath = (): string[] => {
|
||||
return StorageModel.getPath(
|
||||
"connectionModel",
|
||||
StorageModelSubPath.ConnectionModel,
|
||||
filePaths.connectionModel.reconnectAddress
|
||||
);
|
||||
};
|
||||
@@ -209,7 +209,7 @@ export default class ConnectionModel {
|
||||
const dirPath = this.getPreviousAddressPath();
|
||||
return this.storageModel.list(dirPath);
|
||||
}
|
||||
|
||||
|
||||
// init
|
||||
constructor(storageModel: StorageModel) {
|
||||
// create frontend
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// this file is responsible for all settings.
|
||||
|
||||
import StorageModel, { filePaths } from "./storageModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "./storageModel";
|
||||
|
||||
export default class SettingsModel {
|
||||
storageModel: StorageModel;
|
||||
@@ -13,7 +13,7 @@ export default class SettingsModel {
|
||||
setName(newValue: string): void {
|
||||
this.username = newValue;
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.username
|
||||
);
|
||||
this.storageModel.write(path, newValue);
|
||||
@@ -22,7 +22,7 @@ export default class SettingsModel {
|
||||
setFirstDayOfWeek(newValue: string): void {
|
||||
this.firstDayOfWeek = newValue;
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.firstDayOfWeek
|
||||
);
|
||||
this.storageModel.write(path, newValue);
|
||||
@@ -31,7 +31,7 @@ export default class SettingsModel {
|
||||
// load
|
||||
loadUsernam(): void {
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.username
|
||||
);
|
||||
const content = this.storageModel.read(path);
|
||||
@@ -40,7 +40,7 @@ export default class SettingsModel {
|
||||
|
||||
loadFirstDayofWeek(): void {
|
||||
const path = StorageModel.getPath(
|
||||
"settingsModel",
|
||||
StorageModelSubPath.SettingsModel,
|
||||
filePaths.settingsModel.firstDayOfWeek
|
||||
);
|
||||
const content = this.storageModel.read(path);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// this file is responsible for reading and writing persistent data.
|
||||
|
||||
import {
|
||||
DATA_VERSION,
|
||||
ValidObject,
|
||||
} from "../Utility/typeSafety";
|
||||
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
|
||||
import { localeCompare, parseValidObject, stringify } from "../Utility/utility";
|
||||
|
||||
export const PATH_COMPONENT_SEPARATOR = "\\";
|
||||
@@ -84,7 +81,6 @@ export default class StorageModel {
|
||||
const content: string | null = this.read(sourcePathComponents);
|
||||
if (content == null) return false;
|
||||
|
||||
|
||||
this.write(destinationPathComponents, content);
|
||||
this.remove(sourcePathComponents);
|
||||
|
||||
@@ -212,10 +208,10 @@ export default class StorageModel {
|
||||
};
|
||||
|
||||
static getPath(
|
||||
locationName: keyof typeof storageLocations,
|
||||
locationName: StorageModelSubPath,
|
||||
filePath: string[]
|
||||
): string[] {
|
||||
return [DATA_VERSION, storageLocations[locationName], ...filePath];
|
||||
return [DATA_VERSION, locationName, ...filePath];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,13 +219,12 @@ export default class StorageModel {
|
||||
export type StorageEntry = { [key: string]: StorageEntry };
|
||||
|
||||
// locations
|
||||
const storageLocations = {
|
||||
connectionModel: "connection",
|
||||
|
||||
chat: "chat",
|
||||
|
||||
settingsModel: "settings",
|
||||
};
|
||||
export enum StorageModelSubPath {
|
||||
Chat = "chat",
|
||||
|
||||
ConnectionModel = "connection",
|
||||
SettingsModel = "settings",
|
||||
}
|
||||
|
||||
export const filePaths = {
|
||||
connectionModel: {
|
||||
|
||||
Reference in New Issue
Block a user