Files
wanderer/web/src/lib/components/settings/url_import_modal.svelte
Flomp 9276690d60 Federation (#327)
* initial commit federation

* more federation

* more federation

* more federation

* completes follow, accept, undo

* add trail create activity

* process trail create activity

* more trail create activity

* adds missing endpoints

* adds update and delete activity

* adds comment activities

* adds activities back

* adds summit logs activities

* deletes follow counts table

* fixes migrations

* fixes migrations

* fixes migrations

* fixes migrations

* adds remote profiles

* ctd

* ctd

* we are getting closer...

* adds public summit logs

* fixes federated trails in lists

* adds remote lists

* adds list activites

* fixes lists

* adds notifications

* adds iri redirect

* fixes comments and summitlogs

* fixes follows and profiles

* adds asynchronous send

* fixes list search

* adds encryption key

* bug fixes

* fixes activity signing

* removes custon activity object types

* adds html editor

* fixes html editor

* fixes display issues on mastodon

* adds federated sharing

* finishes announcements

* fixes small summit log issues

* adds trail likes

* finalizes likes

* fixes images for komoot

* add disable federation option

* adds private profiles

* updates docs

* adds federated comments

* adds trail and comments actvitiypub routes

* adds mentions to editor

* adds mentions to trails, comments, summit logs

* updates theme

* updates theme

* update docs

* update docs

* updates docs

* fixes various frontend problems

* fixes activitypub follows api

* updates docs

* updates docs

---------

Co-authored-by: Christian Beutel <>
2025-06-21 10:09:22 +02:00

98 lines
2.9 KiB
Svelte

<script lang="ts">
import Modal from "$lib/components/base/modal.svelte";
import { trails_upload } from "$lib/stores/trail_store";
import {
processUploadQueue,
uploadStore,
type Upload,
} from "$lib/stores/upload_store.svelte";
import { validator } from "@felte/validator-zod";
import { createForm } from "felte";
import { _ } from "svelte-i18n";
import { z } from "zod";
import TextField from "../base/text_field.svelte";
import Button from "../base/button.svelte";
let modal: Modal;
let loading: boolean = false;
export function openModal() {
setFields("url", "")
setErrors("url", []);
loading = false;
modal.openModal();
}
const { form, errors, setFields, setErrors } = createForm<{
url: string;
}>({
initialValues: { url: "" },
extend: validator({
schema: z.object({
url: z.string().min(1, "required").url("not-a-valid-url"),
}),
}),
onSubmit: async (form) => {
try {
loading = true;
const r = await fetch("/api/v1/trail/download", {
method: "POST",
body: JSON.stringify({ url: form.url }),
});
if (!r.ok) {
throw new Error(`Failed to fetch file: ${r.statusText}`);
}
const blob = await r.blob();
const fileName =
form.url.split("/").pop() ||
"url-import-file-" + new Date().getTime();
const file = new File([blob], fileName, { type: blob.type });
const u: Upload = {
file: file,
progress: 0,
status: "enqueued",
function: trails_upload,
};
uploadStore.enqueuedUploads.push(u);
await processUploadQueue();
loading = false;
modal.closeModal();
} catch (error) {
console.error("Error:", error);
}
},
});
</script>
<Modal
id="url-import-modal"
size="md:min-w-sm"
title={$_("from-url")}
bind:this={modal}
>
{#snippet content()}
<form id="url-import-form" use:form>
<TextField
name="url"
label="URL"
placeholder="https://..."
error={$errors.url}
></TextField>
</form>
{/snippet}
{#snippet footer()}
<div class="flex items-center gap-4">
<button type="button" class="btn-secondary" onclick={() => modal.closeModal()}
>{$_("cancel")}</button
>
<Button primary type="submit" form="url-import-form" {loading}>{$_("import")}</Button>
</div>
{/snippet}</Modal
>