working on android
This commit is contained in:
parent
08d79f0674
commit
2371ee64d7
54
main.ts
54
main.ts
@ -1,4 +1,5 @@
|
|||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import * as fs from "fs";
|
||||||
import {
|
import {
|
||||||
App,
|
App,
|
||||||
Modal,
|
Modal,
|
||||||
@ -11,7 +12,11 @@ import {
|
|||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
import * as CodeMirror from "codemirror";
|
import * as CodeMirror from "codemirror";
|
||||||
|
|
||||||
import { ListObjectsCommand, S3Client } from "@aws-sdk/client-s3";
|
import {
|
||||||
|
S3Client,
|
||||||
|
ListObjectsCommand,
|
||||||
|
PutObjectCommand,
|
||||||
|
} from "@aws-sdk/client-s3";
|
||||||
|
|
||||||
interface SaveRemotePluginSettings {
|
interface SaveRemotePluginSettings {
|
||||||
s3Endpoint: string;
|
s3Endpoint: string;
|
||||||
@ -47,8 +52,9 @@ export default class SaveRemotePlugin extends Plugin {
|
|||||||
|
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
|
|
||||||
|
|
||||||
this.addRibbonIcon("dice", "Save Remote Plugin", async () => {
|
this.addRibbonIcon("dice", "Save Remote Plugin", async () => {
|
||||||
|
// console.log(this.app.vault.getFiles());
|
||||||
|
// console.log(this.app.vault.getAllLoadedFiles());
|
||||||
new Notice(`checking connection`);
|
new Notice(`checking connection`);
|
||||||
|
|
||||||
const s3Client = new S3Client({
|
const s3Client = new S3Client({
|
||||||
@ -59,21 +65,43 @@ export default class SaveRemotePlugin extends Plugin {
|
|||||||
secretAccessKey: this.settings.s3SecretAccessKey,
|
secretAccessKey: this.settings.s3SecretAccessKey,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(s3Client)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await s3Client.send(
|
const allFilesAndFolders = this.app.vault.getAllLoadedFiles();
|
||||||
new ListObjectsCommand({
|
for (const fileOrFolder of allFilesAndFolders) {
|
||||||
Bucket: this.settings.s3BucketName,
|
if (fileOrFolder.path === "/") {
|
||||||
})
|
console.log('ignore "/"');
|
||||||
);
|
} else if ("children" in fileOrFolder) {
|
||||||
this.cm.replaceRange(
|
// folder
|
||||||
getTextToInsert(data),
|
console.log(`folder ${fileOrFolder.path}/`);
|
||||||
CodeMirror.Pos(this.cm.lastLine())
|
new Notice(`folder ${fileOrFolder.path}/`);
|
||||||
);
|
|
||||||
new Notice("good!");
|
const results = await s3Client.send(
|
||||||
|
new PutObjectCommand({
|
||||||
|
Bucket: this.settings.s3BucketName,
|
||||||
|
Key: `${fileOrFolder.path}/`,
|
||||||
|
Body: "",
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// file
|
||||||
|
console.log(`file ${fileOrFolder.path}`);
|
||||||
|
const strContent = await this.app.vault.adapter.read(
|
||||||
|
fileOrFolder.path
|
||||||
|
);
|
||||||
|
new Notice(`file ${fileOrFolder.path}`);
|
||||||
|
const results = await s3Client.send(
|
||||||
|
new PutObjectCommand({
|
||||||
|
Bucket: this.settings.s3BucketName,
|
||||||
|
Key: `${fileOrFolder.path}`,
|
||||||
|
Body: strContent,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Error", err);
|
console.log("Error", err);
|
||||||
|
new Notice(`${err}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user