-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auth, init folders, sync command and ribbonButton added [beta]
- Loading branch information
0 parents
commit e75730d
Showing
11 changed files
with
979 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 4 | ||
tab_width = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
npm node_modules | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"env": { "node": true }, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"no-prototype-builtins": "off", | ||
"@typescript-eslint/no-empty-function": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# vscode | ||
.vscode | ||
|
||
# Intellij | ||
*.iml | ||
.idea | ||
|
||
# npm | ||
node_modules | ||
|
||
# Don't include the compiled main.js file in the repo. | ||
# They should be uploaded to GitHub releases instead. | ||
main.js | ||
|
||
# Exclude sourcemaps | ||
*.map | ||
|
||
# obsidian | ||
data.json | ||
|
||
# Exclude macOS Finder (System Explorer) View States | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
import { requestUrl } from "obsidian"; | ||
|
||
const getVaultId = async (accessToken, vault, root = null) => { | ||
const response = await requestUrl({ | ||
url: | ||
"https://www.googleapis.com/drive/v3/files?q=mimeType%20%3D%20'application%2Fvnd.google-apps.folder'" + | ||
(root != null ? `%20and%20'${root}'%20in%20parents` : ""), | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}).catch((e) => console.log(e)); | ||
const list = response.json.files; | ||
var vaultFolder = list.filter((file) => file.name == vault); | ||
var vaultId = vaultFolder.length ? vaultFolder[0].id : "NOT FOUND"; | ||
return vaultId; | ||
}; | ||
|
||
const uploadFile = async ( | ||
accessToken, | ||
fileName, | ||
buffer = null, | ||
parentId = null | ||
) => { | ||
const response = await requestUrl({ | ||
url: "https://www.googleapis.com/drive/v3/files?uploadType=multipart", | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
"Content-Type": "application/json", | ||
}, | ||
|
||
body: JSON.stringify({ | ||
//mimeType: "text/pain", | ||
name: fileName, | ||
parents: parentId ? [parentId] : [], | ||
}), | ||
}).catch((e) => console.log(e)); | ||
var id = response.json.id; | ||
if (buffer) { | ||
// upload the metadata | ||
await requestUrl({ | ||
url: `https://www.googleapis.com/upload/drive/v3/files/${id}`, | ||
method: "PATCH", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
|
||
body: buffer, | ||
}).catch((e) => console.log(e)); | ||
} | ||
return id; | ||
}; | ||
|
||
const modifyFile = async (accessToken, fileId, buffer) => { | ||
var res = await requestUrl({ | ||
url: `https://www.googleapis.com/upload/drive/v3/files/${fileId}`, | ||
method: "PATCH", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
|
||
body: buffer, | ||
}).catch((e) => console.log(e)); | ||
return res; | ||
}; | ||
const renameFile = async (accessToken, fileId, newName) => { | ||
const response = await requestUrl({ | ||
url: `https://www.googleapis.com/drive/v3/files/${fileId}`, | ||
method: "PATCH", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
"Content-Type": "application/json", | ||
}, | ||
|
||
body: JSON.stringify({ | ||
name: newName, | ||
}), | ||
}).catch((e) => console.log(e)); | ||
var id = response.json.id; | ||
return id; | ||
}; | ||
|
||
const deleteFile = async (accessToken, fileId) => { | ||
const response = await requestUrl({ | ||
url: `https://www.googleapis.com/drive/v3/files/${fileId}`, | ||
method: "DELETE", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
"Content-Type": "application/json", | ||
}, | ||
}).catch((e) => console.log(e)); | ||
}; | ||
|
||
const uploadFolder = async (accessToken, foldername, rootId = null) => { | ||
const response = await requestUrl({ | ||
url: "https://www.googleapis.com/drive/v3/files?uploadType=multipart", | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
"Content-Type": "application/json", | ||
}, | ||
|
||
body: JSON.stringify({ | ||
mimeType: "application/vnd.google-apps.folder", | ||
name: foldername, | ||
parents: rootId ? [rootId] : [], | ||
}), | ||
}).catch((e) => console.log(e)); | ||
|
||
var id = response.json.id; | ||
return id; | ||
}; | ||
|
||
const getFilesList = async (accessToken, vault) => { | ||
const response = await requestUrl({ | ||
url: | ||
"https://www.googleapis.com/drive/v3/files" + | ||
(vault != null ? `?q='${vault}'%20in%20parents` : ""), | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
return response.json.files; | ||
}; | ||
|
||
const getFoldersList = async (accessToken, vault = null) => { | ||
const response = await requestUrl({ | ||
url: | ||
"https://www.googleapis.com/drive/v3/files?q=mimeType%20%3D%20'application%2Fvnd.google-apps.folder'" + | ||
(vault != null ? `%20and%20'${vault}'%20in%20parents` : ""), | ||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
return response.json.files; | ||
}; | ||
const getFile = async (accessToken, fileId) => { | ||
const responseBuffer = await requestUrl({ | ||
url: | ||
"https://www.googleapis.com/drive/v3/files/" + | ||
fileId + | ||
"?alt=media", | ||
|
||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
const responseName = await requestUrl({ | ||
url: "https://www.googleapis.com/drive/v3/files/" + fileId, | ||
|
||
method: "GET", | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
return [responseName.json.name, responseBuffer.arrayBuffer]; | ||
}; | ||
export { | ||
getVaultId, | ||
getFilesList, | ||
getFoldersList, | ||
uploadFile, | ||
uploadFolder, | ||
getFile, | ||
renameFile, | ||
deleteFile, | ||
modifyFile, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import esbuild from "esbuild"; | ||
import process from "process"; | ||
import builtins from 'builtin-modules' | ||
|
||
const banner = | ||
`/* | ||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD | ||
if you want to view the source, please visit the github repository of this plugin | ||
*/ | ||
`; | ||
|
||
const prod = (process.argv[2] === 'production'); | ||
|
||
esbuild.build({ | ||
banner: { | ||
js: banner, | ||
}, | ||
entryPoints: ['main.ts'], | ||
bundle: true, | ||
external: [ | ||
'obsidian', | ||
'electron', | ||
'@codemirror/autocomplete', | ||
'@codemirror/collab', | ||
'@codemirror/commands', | ||
'@codemirror/language', | ||
'@codemirror/lint', | ||
'@codemirror/search', | ||
'@codemirror/state', | ||
'@codemirror/view', | ||
'@lezer/common', | ||
'@lezer/highlight', | ||
'@lezer/lr', | ||
...builtins], | ||
format: 'cjs', | ||
watch: !prod, | ||
target: 'es2018', | ||
logLevel: "info", | ||
sourcemap: prod ? false : 'inline', | ||
treeShaking: true, | ||
outfile: 'main.js', | ||
}).catch(() => process.exit(1)); |
Oops, something went wrong.