allow skipping empty file in onedrive

This commit is contained in:
fyears 2024-05-18 12:03:53 +08:00
parent a48440e60b
commit 9d8e2af7b9
7 changed files with 55 additions and 7 deletions

View File

@ -89,6 +89,7 @@ export interface OnedriveConfig {
username: string;
credentialsShouldBeDeletedAtTime?: number;
remoteBaseDir?: string;
emptyFile: "skip" | "error";
}
export interface WebdisConfig {
@ -230,6 +231,7 @@ export interface Entity {
hash?: string;
etag?: string;
synthesizedFolder?: boolean;
synthesizedFile?: boolean;
}
export interface UploadedType {

View File

@ -32,6 +32,7 @@ export const DEFAULT_ONEDRIVE_CONFIG: OnedriveConfig = {
deltaLink: "",
username: "",
credentialsShouldBeDeletedAtTime: 0,
emptyFile: "skip",
};
////////////////////////////////////////////////////////////////////////////////
@ -344,6 +345,7 @@ const fromDriveItemToEntity = (x: DriveItem, remoteBaseDir: string): Entity => {
mtimeCli: mtimeCli,
size: isFolder ? 0 : x.size!,
sizeRaw: isFolder ? 0 : x.size!,
synthesizedFile: false,
// hash: ?? // TODO
};
};
@ -785,7 +787,8 @@ export class FakeFsOnedrive extends FakeFs {
content,
mtime,
ctime,
key
key,
this.onedriveConfig.emptyFile
);
}
@ -794,12 +797,26 @@ export class FakeFsOnedrive extends FakeFs {
content: ArrayBuffer,
mtime: number,
ctime: number,
origKey: string
origKey: string,
emptyFile: "skip" | "error"
): Promise<Entity> {
if (content.byteLength === 0) {
throw Error(
`${origKey}: Empty file is not allowed in OneDrive, and please write something in it.`
);
if (emptyFile === "error") {
throw Error(
`${origKey}: Empty file is not allowed in OneDrive, and please write something in it.`
);
} else {
return {
key: origKey,
keyRaw: origKey,
mtimeSvr: mtime,
mtimeCli: mtime,
size: 0,
sizeRaw: 0,
synthesizedFile: true,
// hash: ?? // TODO
};
}
}
const ctimeStr = new Date(ctime).toISOString();

View File

@ -219,8 +219,12 @@
"settings_onedrive_auth": "Auth",
"settings_onedrive_auth_desc": "Auth.",
"settings_onedrive_auth_button": "Auth",
"settings_onedrive_connect_succ": "Great! We can connect to Onedrive!",
"settings_onedrive_connect_fail": "We cannot connect to Onedrive.",
"settings_onedrive_connect_succ": "Great! We can connect to OneDrive!",
"settings_onedrive_connect_fail": "We cannot connect to OneDrive.",
"settings_onedrive_emptyfile": "Empty File Handling",
"settings_onedrive_emptyfile_desc": "OneDrive doesn't allow uploading empty file (even in its official website). Do you want to show up errors or silently skip the empty files?",
"settings_onedrive_emptyfile_skip": "Skip",
"settings_onedrive_emptyfile_error": "Error and abort",
"settings_webdav": "Remote For Webdav",
"settings_webdav_disclaimer1": "Disclaimer: The information is stored locally. Other malicious/harmful/faulty plugins may read the info. If you see any unintentional access to your webdav server, please immediately change the username and password.",
"settings_webdav_cors_os": "Obsidian desktop>=0.13.25 or iOS>=1.1.1 or Android>=1.2.1 supports bypassing CORS locally. But you are using an old version, and you're suggested to upgrade Obsidian.",

View File

@ -220,6 +220,10 @@
"settings_onedrive_auth_button": "鉴权",
"settings_onedrive_connect_succ": "很好!我们可连接上 OneDrive",
"settings_onedrive_connect_fail": "我们未能连接上 OneDrive。",
"settings_onedrive_emptyfile": "空文件处理",
"settings_onedrive_emptyfile_desc": "OneDrive 不允许上传空文件(即使官网也是不允许的)。那么你想跳过空文件还是返回错误?",
"settings_onedrive_emptyfile_skip": "跳过",
"settings_onedrive_emptyfile_error": "返回错误和中断",
"settings_webdav": "Webdav 设置",
"settings_webdav_disclaimer1": "声明:您所输入的信息存储于本地。其它有害的或者出错的插件,是有可能读取到这些信息的。如果您发现了 Webdav 服务器有不符合预期的访问,请立刻修改用户名和密码。",
"settings_webdav_cors_os": "Obsidian 桌面版>=0.13.25 或 iOS>=1.1.1 或 Android>=1.2.1 支持跳过 CORS 设置。但您正在使用旧版,建议升级。",

View File

@ -219,6 +219,10 @@
"settings_onedrive_auth_button": "鑑權",
"settings_onedrive_connect_succ": "很好!我們可連線上 OneDrive",
"settings_onedrive_connect_fail": "我們未能連線上 OneDrive。",
"settings_onedrive_emptyfile": "空檔案處理",
"settings_onedrive_emptyfile_desc": "OneDrive 不允許上傳空檔案(即使官網也是不允許的)。那麼你想跳過空檔案還是返回錯誤?",
"settings_onedrive_emptyfile_skip": "跳過",
"settings_onedrive_emptyfile_error": "返回錯誤和中斷",
"settings_webdav": "Webdav 設定",
"settings_webdav_disclaimer1": "宣告:您所輸入的資訊儲存於本地。其它有害的或者出錯的外掛,是有可能讀取到這些資訊的。如果您發現了 Webdav 伺服器有不符合預期的訪問,請立刻修改使用者名稱和密碼。",
"settings_webdav_cors_os": "Obsidian 桌面版>=0.13.25 或 iOS>=1.1.1 或 Android>=1.1.1 支援跳過 CORS 設定。但您正在使用舊版,建議升級。",

View File

@ -855,6 +855,9 @@ export default class RemotelySavePlugin extends Plugin {
if (this.settings.onedrive.remoteBaseDir === undefined) {
this.settings.onedrive.remoteBaseDir = "";
}
if (this.settings.onedrive.emptyFile === undefined) {
this.settings.onedrive.emptyFile = "skip";
}
if (this.settings.webdav.manualRecursive === undefined) {
this.settings.webdav.manualRecursive = true;
}

View File

@ -1418,6 +1418,20 @@ export class RemotelySaveSettingTab extends PluginSettingTab {
});
});
new Setting(onedriveDiv)
.setName(t("settings_onedrive_emptyfile"))
.setDesc(t("settings_onedrive_emptyfile_desc"))
.addDropdown(async (dropdown) => {
dropdown
.addOption("skip", t("settings_onedrive_emptyfile_skip"))
.addOption("error", t("settings_onedrive_emptyfile_error"))
.setValue(this.plugin.settings.onedrive.emptyFile)
.onChange(async (val) => {
this.plugin.settings.onedrive.emptyFile = val as any;
await this.plugin.saveSettings();
});
});
new Setting(onedriveDiv)
.setName(t("settings_checkonnectivity"))
.setDesc(t("settings_checkonnectivity_desc"))