Skip to content

Commit

Permalink
feat(frontend): log sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
thewander02 committed Oct 18, 2024
1 parent 610c06f commit 51d364b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apps/frontend/src/pages/servers/manage/[id]/files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@
</div>
<div class="flex gap-2">
<Button
v-if="editingFile.path.startsWith('logs') && editingFile.path.endsWith('.log')"
v-tooltip="'Share your mc log'"
icon-only
transparent
@click="requestShareLink"
>
<ShareIcon />
</Button>
<ButtonStyled type="transparent">
<OverflowMenu
class="btn-dropdown-animation flex items-center gap-1 rounded-xl bg-transparent px-2 py-1"
Expand Down Expand Up @@ -374,6 +383,7 @@ import {
ArrowBigUpDashIcon,
DownloadIcon,
TrashIcon,
ShareIcon,
} from "@modrinth/assets";
import { Button, Modal, ButtonStyled, OverflowMenu } from "@modrinth/ui";
import { useInfiniteScroll } from "@vueuse/core";
Expand Down Expand Up @@ -552,6 +562,34 @@ const fileContent = ref("");
const editingFile = ref<any>(null);
const closeEditor = ref(false);
const requestShareLink = async () => {
try {
const response = (await $fetch("https://api.mclo.gs/1/log", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams({
content: fileContent.value,
}),
})) as any;
if (response.success) {
navigator.clipboard.writeText(response.url);
addNotification({
group: "files",
title: "Log URL copied",
text: "Your log file URL has been copied to your clipboard.",
type: "success",
});
} else {
throw new Error(response.error);
}
} catch (error) {
console.error("Error sharing file:", error);
}
};
const showCreateModal = (type: "file" | "directory") => {
newItemType.value = type;
newItemName.value = "";
Expand Down

0 comments on commit 51d364b

Please sign in to comment.