diff --git a/README.md b/README.md index 03f8ab6..ba5fb54 100644 --- a/README.md +++ b/README.md @@ -18,19 +18,22 @@ This plugin is for uploading **images** to hosting platform or **files** to Gith ## State -| file hosting | image hosting | Multi language support | -| ------------------------------------ | --------------------------------- | --------------------------------------------------- | -| [GitHub](https://github.com/) | [Imgur](https://imgur.com/) | 简体中文 | -| [Clouinary](https://cloudinary.com/) | [SM.MS](https://smms.app/) | 繁體中文 [@emisjerry](https://github.com/emisjerry) | -| [Catbox](https://catbox.moe/) | [ImgURL](https://www.imgurl.org/) | English | -| | [imgbb](https://imgbb.com/) | | -| | [chevereto](https://chevereto.com/) | | +| file hosting | image hosting | Multi language support | +| ------------------------------------ | ----------------------------------- | --------------------------------------------------- | +| [GitHub](https://github.com/) | [Imgur](https://imgur.com/) | 简体中文 | +| [Clouinary](https://cloudinary.com/) | [SM.MS](https://smms.app/) | 繁體中文 [@emisjerry](https://github.com/emisjerry) | +| [Catbox](https://catbox.moe/) | [ImgURL](https://www.imgurl.org/) | English | +| [AList](https://alist.nn.ci/zh/) | [imgbb](https://imgbb.com/) | | +| | [chevereto](https://chevereto.com/) | | + +### 2.17 + +support [AList](https://alist.nn.ci/zh/), thanks to [Linnnkkk](https://github.com/Linnnkkk). ### V2.16 Adapted to chevereto v3 - ### V2.15 support [chevereto](https://chevereto.com/) @@ -141,4 +144,4 @@ Thank you! | [obsidian-cloudinary-uploader](https://github.com/jordanhandy/obsidian-cloudinary-uploader) | [Github REST API](https://docs.github.com/cn/rest) | [jsdelivr](https://www.jsdelivr.com/) | | [SM.MS](https://smms.app/) | [ImgURL](https://www.imgurl.org/) | [Clouinary](https://cloudinary.com/) | | [Imgur](https://imgur.com/) | [imgbb](https://imgbb.com/) | [obsidian-imgur-plugin](https://github.com/gavvvr/obsidian-imgur-plugin) | -| [Catbox](https://catbox.moe/) | [chevereto](https://chevereto.com/) | | +| [Catbox](https://catbox.moe/) | [chevereto](https://chevereto.com/) | [AList](https://alist.nn.ci/zh/) | diff --git a/docs/assets/obsidian-settings-page.png b/docs/assets/obsidian-settings-page.png deleted file mode 100644 index ee0577f..0000000 Binary files a/docs/assets/obsidian-settings-page.png and /dev/null differ diff --git a/manifest.json b/manifest.json index 2c19d1a..f1c5bb6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "emo-uploader", "name": "Emo", - "version": "2.16", + "version": "2.17", "minAppVersion": "0.15.6", "description": "Embed markdown online file/image links. This plugin is for uploading images to hosting or files to github in Obsidian.", "author": "yaleiyale", diff --git a/package.json b/package.json index 5f2d95d..40982b2 100755 --- a/package.json +++ b/package.json @@ -10,6 +10,9 @@ "keywords": [], "author": "yaleiyale", "license": "MIT", + "dependencies": { + "js-sha256": "^0.10.1" + }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.61.0", "eslint": "^8.44.0", diff --git a/src/config.ts b/src/config.ts index f100736..6cdded0 100644 --- a/src/config.ts +++ b/src/config.ts @@ -30,7 +30,7 @@ export enum HostingProvider { // target hosting ImgURL = 'ImgURL', Imgbb = 'imgbb', Chevereto = 'chevereto', - Alist = 'alist' + Alist = 'AList' } export const DEFAULT_SETTINGS: Config = { diff --git a/src/fragment/fragment-alist.ts b/src/fragment/fragment-alist.ts index 9e4bcfc..e07015e 100644 --- a/src/fragment/fragment-alist.ts +++ b/src/fragment/fragment-alist.ts @@ -11,12 +11,13 @@ export class AlistFragment extends EmoFragment { display (el: HTMLElement, plugin: Emo): void { const parms = plugin.config.alist_parms - el.createEl('h3', { text: 'Alist Settings'}) + el.createEl('h3', { text: t('AList Settings') }) new Setting(el) .setName(t('domain')) .addText((text) => { text + .setPlaceholder('https://alist.example.com') .setValue(parms.required.domain) .onChange(async (value) => { parms.required.domain = value @@ -25,7 +26,7 @@ export class AlistFragment extends EmoFragment { }) new Setting(el) - .setName('username') + .setName(t('username')) .addText((text) => { text .setValue(parms.required.username) @@ -36,7 +37,7 @@ export class AlistFragment extends EmoFragment { }) new Setting(el) - .setName('password') + .setName(t('password')) .addText((text) => { text .setValue(parms.required.password) @@ -47,7 +48,7 @@ export class AlistFragment extends EmoFragment { }) new Setting(el) - .setName('uploadPath') + .setName(t('uploadPath')) .addText((text) => { text .setValue(parms.required.uploadPath) @@ -56,6 +57,5 @@ export class AlistFragment extends EmoFragment { await plugin.saveSettings() }) }) - } } diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 74807d4..08937f3 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -54,5 +54,10 @@ export default { // fragment-catbox.ts 'Catbox Settings': 'Catbox Settings', // fragment-chevereto.ts - 'Chevereto Settings': 'Chevereto Settings' + 'Chevereto Settings': 'Chevereto Settings', + // fragment-alist.ts + 'AList Settings': 'Alist Settings', + username: 'username', + password: 'password', + uploadPath: 'uploadPath' } diff --git a/src/lang/locale/zh-cn.ts b/src/lang/locale/zh-cn.ts index 7397cfc..0da6a3b 100644 --- a/src/lang/locale/zh-cn.ts +++ b/src/lang/locale/zh-cn.ts @@ -54,5 +54,10 @@ export default { // fragment-catbox.ts 'Catbox Settings': 'Catbox配置', // fragment-chevereto.ts - 'Chevereto Settings': 'Chevereto配置' + 'Chevereto Settings': 'Chevereto配置', + // fragment-alist.ts + 'AList Settings': 'Alist配置', + username: '用户名', + password: '密码', + uploadPath: '上传路径' } diff --git a/src/lang/locale/zh-tw.ts b/src/lang/locale/zh-tw.ts index 6c57abf..9be22f8 100644 --- a/src/lang/locale/zh-tw.ts +++ b/src/lang/locale/zh-tw.ts @@ -54,5 +54,10 @@ export default { // fragment-catbox.ts 'Catbox Settings': 'Catbox配置', // fragment-chevereto.ts - 'Chevereto Settings': 'Chevereto配置' + 'Chevereto Settings': 'Chevereto配置', + // fragment-alist.ts + 'AList Settings': 'Alist配置', + username: '用戶名', + password: '密碼', + uploadPath: '上傳路徑' } diff --git a/src/parms/parms-alist.ts b/src/parms/parms-alist.ts index 388e18e..5fcc547 100644 --- a/src/parms/parms-alist.ts +++ b/src/parms/parms-alist.ts @@ -13,10 +13,9 @@ interface Required { export const ALIST_DEFAULT_PARMS: AlistParms = { required: { - domain: 'https://alist.example.com', + domain: '', username: '', password: '', - uploadPath: '上传的相对路径', + uploadPath: '' } } - diff --git a/src/uploader/uploader-alist.ts b/src/uploader/uploader-alist.ts index 105f5f6..dc34eb1 100644 --- a/src/uploader/uploader-alist.ts +++ b/src/uploader/uploader-alist.ts @@ -13,14 +13,13 @@ export class AlistUploader extends EmoUploader { this.parms = alistParms } - async upload (file: File): Promise { // 获取token const token = await this.getToken() // 新建文件夹 const determine = await this.determine(file) - if (determine != 'success') { - await this.mkdirFile(file) + if (determine !== 'success') { + await this.mkdirFile(file) } // 上传文件 await this.putFile(file) @@ -28,17 +27,17 @@ export class AlistUploader extends EmoUploader { await this.refreshDir(file) // 重命名文件 let newName = file.name - if (file.name == 'image.png'){ - newName = await this.renameFile(file) + if (file.name === 'image.png') { + newName = await this.renameFile(file) } - + const extension = await this.getFileExtension(file) const req: RequestUrlParam = { url: `${this.parms.required.domain}/api/fs/get`, method: 'POST', headers: { - 'Authorization': token , - 'Content-Type': 'application/json', + Authorization: token, + 'Content-Type': 'application/json' }, body: JSON.stringify({ path: `/${this.parms.required.uploadPath}/${extension}/${newName}` @@ -49,7 +48,7 @@ export class AlistUploader extends EmoUploader { request(req).then(async res => { const json = JSON.parse(res) // 赋给markdownText - const markdownText = `![${newName}](${json.data.raw_url})` + const markdownText = `![${newName}](${json.data.raw_url})` resolve(markdownText) }).catch(err => { reject(err) @@ -57,8 +56,8 @@ export class AlistUploader extends EmoUploader { }) } - //第二部分 - //获取token + // 第二部分 + // 获取token async getToken (): Promise { const req: RequestUrlParam = { url: `${this.parms.required.domain}/api/auth/login/hash`, @@ -82,23 +81,22 @@ export class AlistUploader extends EmoUploader { }) } - - //文件类型 - async getFileExtension(file: File): Promise { + // 文件类型 + async getFileExtension (file: File): Promise { const filename = file.name const match = filename.match(/\.([^.]+)$/) - return match ? match[1] : "" + return (match != null) ? match[1] : '' } - //判断文件夹是否存在 + // 判断文件夹是否存在 async determine (file: File): Promise { const extension = await this.getFileExtension(file) const req: RequestUrlParam = { url: `${this.parms.required.domain}/api/fs/get`, method: 'POST', headers: { - 'Authorization': await this.getToken(), - 'Content-Type': 'application/json', + Authorization: await this.getToken(), + 'Content-Type': 'application/json' }, body: JSON.stringify({ path: `/${this.parms.required.uploadPath}/${extension}` @@ -114,23 +112,21 @@ export class AlistUploader extends EmoUploader { }) } - async mkdirFile (file: File): Promise { - const extension = await this.getFileExtension(file) - const req: RequestUrlParam = { - url: `${this.parms.required.domain}/api/fs/mkdir`, - method: 'POST', - headers: { - 'Authorization': await this.getToken(), - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - path: `/${this.parms.required.uploadPath}/${extension}`, - }) - } - await request(req) // 发送请求并返回链接 - } - - + async mkdirFile (file: File): Promise { + const extension = await this.getFileExtension(file) + const req: RequestUrlParam = { + url: `${this.parms.required.domain}/api/fs/mkdir`, + method: 'POST', + headers: { + Authorization: await this.getToken(), + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + path: `/${this.parms.required.uploadPath}/${extension}` + }) + } + await request(req) // 发送请求并返回链接 + } // 上传文件 async putFile (file: File): Promise { @@ -141,7 +137,7 @@ export class AlistUploader extends EmoUploader { url: `${this.parms.required.domain}/api/fs/form`, method: 'PUT', headers: { - 'Authorization': await this.getToken(), + Authorization: await this.getToken(), 'Content-Type': CONTENT_TYPE_FORMDATA, 'File-Path': encodeURIComponent(`/${this.parms.required.uploadPath}/${extension}/${file.name}`), 'As-Task': 'true' @@ -151,7 +147,7 @@ export class AlistUploader extends EmoUploader { await request(req) // 发送请求并返回链接 } - //第三部分 + // 第三部分 // 刷新目录 async refreshDir (file: File): Promise { const extension = await this.getFileExtension(file) @@ -159,19 +155,18 @@ export class AlistUploader extends EmoUploader { url: `${this.parms.required.domain}/api/fs/list`, method: 'POST', headers: { - 'Authorization': await this.getToken(), - 'Content-Type': 'application/json', + Authorization: await this.getToken(), + 'Content-Type': 'application/json' }, body: JSON.stringify({ path: `/${this.parms.required.uploadPath}/${extension}`, page: 1, - password: "", + password: '', per_page: 0, - refresh: true, + refresh: true }) } await request(req) - } // 重命名文件 @@ -188,8 +183,8 @@ export class AlistUploader extends EmoUploader { url: `${this.parms.required.domain}/api/fs/rename`, method: 'POST', headers: { - 'Authorization': await this.getToken(), - 'Content-Type': 'application/json', + Authorization: await this.getToken(), + 'Content-Type': 'application/json' }, body: JSON.stringify({ name: newName, @@ -200,6 +195,4 @@ export class AlistUploader extends EmoUploader { await request(req) return newName } - } -