Skip to content

Commit

Permalink
always add pasteId, even when errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cs8898 committed Jan 10, 2024
1 parent a7a76ac commit 385a5fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 5 additions & 4 deletions pages/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ const route = useRoute();
const loadedPaste: Ref<Paste | undefined> = ref();
const currentPaste: Ref<Paste | undefined> = ref();
var pasteId: string|undefined;
if (route.params.slug.length > 0) {
const { data } = await useFetch(`/api/pastes/${route.params.slug[0]}`);
pasteId = route.params.slug[0];
const { data } = await useFetch(`/api/pastes/${pasteId}`);
loadedPaste.value = data.value as Paste;
}
Expand All @@ -76,15 +78,15 @@ onMounted(async () => {
// TODO Decode Error
}
} catch (e) {
decryptResolve({ content: getPlaceholderText(`${e}`), language: "markdown" })
decryptResolve({ id: pasteId, content: getPlaceholderText(`${e}`), language: "markdown" })
}
} else {
// TODO No Key Provided
}
}
} else {
if (loadedPaste.value === null) {
decryptResolve({ content: getPlaceholderText("Error loading Paste!"), language: "markdown" })
decryptResolve({ id: pasteId, content: getPlaceholderText("Error loading Paste!"), language: "markdown" })
} else {
decryptResolve({ content: getPlaceholderText(), language: "markdown" });
}
Expand All @@ -93,7 +95,6 @@ onMounted(async () => {
function editorInited() {
decryptPromise.then((paste) => {
console.log("Has paste", paste);
currentPaste.value = paste;
editorRef.value?.setSource(currentPaste.value.content);
changeLanguage(currentPaste.value.language);
Expand Down
10 changes: 6 additions & 4 deletions pages/diff/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ const route = useRoute();
const loadedPaste: Ref<Paste | undefined> = ref();
const currentPaste: Ref<Paste | undefined> = ref();
var pasteId: string | undefined;
if (route.params.slug.length > 0) {
const { data } = await useFetch(`/api/pastes/${route.params.slug[0]}`);
pasteId = route.params.slug[0];
const { data } = await useFetch(`/api/pastes/${pasteId}`);
loadedPaste.value = data.value as Paste;
}
Expand All @@ -76,15 +78,15 @@ onMounted(async () => {
// TODO Decode Error
}
} catch (e) {
decryptResolve({ content: getPlaceholderText(`${e}`), language: "markdown" })
decryptResolve({ id: pasteId, content: getPlaceholderText(`${e}`), language: "markdown" })
}
} else {
// TODO No Key Provided
}
}
} else {
if (loadedPaste.value === null) {
decryptResolve({ content: getPlaceholderText("Error loading Paste!"), language: "markdown" })
decryptResolve({ id: pasteId, content: getPlaceholderText("Error loading Paste!"), language: "markdown" })
} else {
decryptResolve({ content: getPlaceholderText(), language: "markdown" });
}
Expand All @@ -109,7 +111,7 @@ async function saveFile() {
// TODO no pasteLoaded
return;
}
const {original, modified} = editorRef.value!.getSource();
const { original, modified } = editorRef.value!.getSource();
currentPaste.value.content = original;
currentPaste.value.modified = modified;
currentPaste.value.language = currentLanguage.value;
Expand Down

0 comments on commit 385a5fa

Please sign in to comment.