mirror of
https://github.com/jvsteiner/send-note.git
synced 2026-07-22 11:20:26 +00:00
reduced console logging, and added better status messages
This commit is contained in:
parent
43ad0e09b9
commit
a7852fd78a
2 changed files with 4 additions and 86 deletions
35
src/main.ts
35
src/main.ts
|
|
@ -256,7 +256,7 @@ export default class SendNotePlugin extends Plugin {
|
|||
if (shareLink) {
|
||||
// The note is already shared, copy the link to the clipboard
|
||||
await navigator.clipboard.writeText(shareLink);
|
||||
new StatusMessage("📋 Shared link copied to clipboard");
|
||||
new StatusMessage("📋 Shared link copied to clipboard", StatusType.Default, 2000);
|
||||
} else {
|
||||
// The note is not already shared, share it first and copy the link to the clipboard
|
||||
await this.uploadNote(false, true);
|
||||
|
|
@ -271,7 +271,7 @@ export default class SendNotePlugin extends Plugin {
|
|||
"Delete shared note?",
|
||||
"Are you sure you want to delete this shared note and the shared link? This will not delete your local note.",
|
||||
async () => {
|
||||
new StatusMessage("Deleting note...");
|
||||
new StatusMessage("Deleting note...", StatusType.Default, 2000);
|
||||
// await this.api.deleteSharedNote(sharedFile.url);
|
||||
|
||||
await this.deletePaste(this.getIdentifier(sharedFile.url));
|
||||
|
|
@ -322,7 +322,7 @@ export default class SendNotePlugin extends Plugin {
|
|||
setIcon(copyIcon, "copy");
|
||||
copyIcon.onclick = async () => {
|
||||
await navigator.clipboard.writeText(shareLink);
|
||||
new StatusMessage("📋 Sending link copied to clipboard");
|
||||
new StatusMessage("📋 Sending link copied to clipboard", StatusType.Default, 2000);
|
||||
};
|
||||
// Delete shared note icon
|
||||
const deleteIcon = iconsEl.createEl("span");
|
||||
|
|
@ -371,38 +371,11 @@ export default class SendNotePlugin extends Plugin {
|
|||
})
|
||||
)
|
||||
.then((data) => {
|
||||
console.log("data", data);
|
||||
new StatusMessage(`Deleted note: ${data.Deleted?.[0]?.Key}`, StatusType.Default, 2000);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("error", err);
|
||||
});
|
||||
// const url = "https://pastebin.com/api/api_post.php";
|
||||
|
||||
// const formData = new URLSearchParams();
|
||||
// // formData.append("api_dev_key", this.settings.pastebinApiKey);
|
||||
// // formData.append("api_user_key", this.settings.pastebinUserKey);
|
||||
// formData.append("api_paste_key", pasteKey);
|
||||
// formData.append("api_option", "delete");
|
||||
|
||||
// try {
|
||||
// const response = await requestUrl({
|
||||
// url: url,
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// "Content-Type": "application/x-www-form-urlencoded",
|
||||
// },
|
||||
// body: formData.toString(),
|
||||
// });
|
||||
|
||||
// const result = await response.text;
|
||||
|
||||
// if (result.trim() === "Paste Removed") {
|
||||
// } else {
|
||||
// console.error("Error deleting paste:", result);
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error("Network or parsing error:", error);
|
||||
// }
|
||||
}
|
||||
|
||||
private generateRandomString(length = 5) {
|
||||
|
|
|
|||
55
src/note.ts
55
src/note.ts
|
|
@ -94,22 +94,9 @@ export default class Note {
|
|||
}
|
||||
});
|
||||
|
||||
// const pastebinData = {
|
||||
// api_dev_key: this.plugin.settings.pastebinApiKey,
|
||||
// api_user_key: this.plugin.settings.pastebinUserKey,
|
||||
// api_option: "paste",
|
||||
// api_paste_private: 1,
|
||||
// api_paste_name: this.file.basename,
|
||||
// api_paste_expire_date: this.plugin.settings.pastebinExpiry,
|
||||
// api_paste_format: "text",
|
||||
// api_paste_code: encodeURIComponent(noteContent),
|
||||
// };
|
||||
|
||||
// const body = this.createQueryString(pastebinData);
|
||||
this.plugin
|
||||
.uploadFile(noteContent, this.file.basename)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
const responseText = res.trim();
|
||||
if (!responseText.startsWith("http")) {
|
||||
throw new Error("Invalid URL response from AWS");
|
||||
|
|
@ -123,7 +110,6 @@ export default class Note {
|
|||
} else {
|
||||
obsidianUrl = `obsidian://send-note?sendurl=${responseText}&filename=${this.file.basename}.md&encrypted=true&key=${encryptionKey}`;
|
||||
}
|
||||
// console.log(obsidianUrl);
|
||||
navigator.clipboard.writeText(obsidianUrl);
|
||||
this.plugin.app.fileManager.processFrontMatter(this.file, (frontmatter) => {
|
||||
if ((frontmatter["send_link"] = true)) {
|
||||
|
|
@ -135,47 +121,6 @@ export default class Note {
|
|||
.catch((err) => {
|
||||
console.error(err);
|
||||
});
|
||||
|
||||
// requestUrl({
|
||||
// url: "https://pastebin.com/api/api_post.php",
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// "Content-Type": "application/x-www-form-urlencoded",
|
||||
// },
|
||||
// body: body,
|
||||
// })
|
||||
// .then((res) => {
|
||||
// const responseText = res.text.trim();
|
||||
// if (!responseText.startsWith("http")) {
|
||||
// throw new Error("Invalid URL response from Pastebin");
|
||||
// }
|
||||
// const urlObj = new URL(responseText);
|
||||
// const pathSegments = urlObj.pathname.split("/");
|
||||
// const suffix = pathSegments[pathSegments.length - 1];
|
||||
// let obsidianUrl = "";
|
||||
// if (shareUnencrypted) {
|
||||
// obsidianUrl = `obsidian://send-note?sendurl=https://pastebin.com/raw/${suffix}&filename=${this.file.basename}.md`;
|
||||
// } else {
|
||||
// obsidianUrl = `obsidian://send-note?sendurl=https://pastebin.com/raw/${suffix}&filename=${this.file.basename}.md&encrypted=true&key=${encryptionKey}`;
|
||||
// }
|
||||
// // console.log(obsidianUrl);
|
||||
// navigator.clipboard.writeText(obsidianUrl);
|
||||
// this.plugin.app.fileManager.processFrontMatter(this.file, (frontmatter) => {
|
||||
// if ((frontmatter["send_link"] = true)) {
|
||||
// frontmatter["send_link"] = obsidianUrl;
|
||||
// }
|
||||
// });
|
||||
// this.plugin.addShareIcons();
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.log("err", err);
|
||||
// this.status = new StatusMessage(
|
||||
// err +
|
||||
// ". The note uploading failed. If you got status 422, it might be because you have exceeded your allowed number of pastes for 24 hours.",
|
||||
// StatusType.Error,
|
||||
// 5 * 1000
|
||||
// );
|
||||
// });
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue