mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 18:20:30 +08:00
Add /raw route for getting images
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { MaybeBlob, Blob } from "@app/lib/project";
|
||||
import type { Blob } from "@app/lib/project";
|
||||
import type { MaybeHighlighted } from "@app/lib/syntax";
|
||||
import type { ProjectRoute } from "@app/lib/router/definitions";
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
export let activeRoute: ProjectRoute;
|
||||
export let blob: Blob;
|
||||
export let getImage: (path: string) => Promise<MaybeBlob>;
|
||||
export let rawPath: string;
|
||||
export let line: string | undefined = undefined;
|
||||
|
||||
const fileExtension = blob.path.split(".").pop() ?? "";
|
||||
@@ -247,7 +247,7 @@
|
||||
<span class="txt-tiny">Binary content</span>
|
||||
</div>
|
||||
{:else if showMarkdown && blob.content}
|
||||
<Readme content={blob.content} {getImage} {activeRoute} />
|
||||
<Readme content={blob.content} {rawPath} {activeRoute} />
|
||||
{:else if content}
|
||||
<table class="code no-scrollbar">
|
||||
{@html toHtml(content)}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
import type { ProjectRoute } from "@app/lib/router/definitions";
|
||||
|
||||
import * as router from "@app/lib/router";
|
||||
import * as utils from "@app/lib/utils";
|
||||
import Button from "@app/components/Button.svelte";
|
||||
import Loading from "@app/components/Loading.svelte";
|
||||
import Placeholder from "@app/components/Placeholder.svelte";
|
||||
@@ -59,15 +58,6 @@
|
||||
browserErrorStore.set(undefined);
|
||||
});
|
||||
|
||||
// Get an image blob based on a relative path.
|
||||
const getImage = async (imagePath: string) => {
|
||||
const finalPath = utils.canonicalize(imagePath, path);
|
||||
return project.getBlob(commit, finalPath).catch(() => {
|
||||
console.warn("Not able to load image blob:", finalPath);
|
||||
return undefined;
|
||||
});
|
||||
};
|
||||
|
||||
const onSelect = async (newPath: string) => {
|
||||
browserErrorStore.set(undefined);
|
||||
// Ensure we don't spend any time in a "loading" state. This means
|
||||
@@ -242,7 +232,11 @@
|
||||
<Loading small center />
|
||||
{:then blob}
|
||||
{#if blob}
|
||||
<Blob {line} {blob} {getImage} {activeRoute} />
|
||||
<Blob
|
||||
{line}
|
||||
{blob}
|
||||
{activeRoute}
|
||||
rawPath={project.getRawPath(commit)} />
|
||||
{/if}
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
<script lang="ts">
|
||||
import type { Blob, Project } from "@app/lib/project";
|
||||
import type { Project } from "@app/lib/project";
|
||||
import type { Issue } from "@app/lib/issue";
|
||||
|
||||
import Authorship from "@app/components/Authorship.svelte";
|
||||
import Avatar from "@app/components/Comment/Avatar.svelte";
|
||||
import Chip from "@app/components/Chip.svelte";
|
||||
import Comment from "@app/components/Comment.svelte";
|
||||
import { formatNodeId, canonicalize, capitalize } from "@app/lib/utils";
|
||||
import { formatNodeId, capitalize } from "@app/lib/utils";
|
||||
import { formatObjectId } from "@app/lib/cobs";
|
||||
|
||||
export let issue: Issue;
|
||||
export let project: Project;
|
||||
|
||||
// Get an image blob based on a relative path.
|
||||
const getImage = async (imagePath: string): Promise<Blob> => {
|
||||
const finalPath = canonicalize(imagePath, "/"); // We only use the root path in issues.
|
||||
const commit = project.branches[project.defaultBranch]; // We suppose that all issues are only looked at on HEAD of the default branch.
|
||||
return project.getBlob(commit, finalPath);
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -140,7 +133,7 @@
|
||||
<main>
|
||||
<div class="comments">
|
||||
{#each issue.discussion as comment}
|
||||
<Comment {comment} {getImage} />
|
||||
<Comment {comment} rawPath={project.getRawPath()} />
|
||||
{/each}
|
||||
</div>
|
||||
<div class="metadata layout-desktop">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" strictEvents>
|
||||
import type { MaybeBlob, Project } from "@app/lib/project";
|
||||
import type { Project } from "@app/lib/project";
|
||||
import type { Session } from "@app/lib/session";
|
||||
|
||||
import * as modal from "@app/lib/modal";
|
||||
@@ -11,7 +11,7 @@
|
||||
import TextInput from "@app/components/TextInput.svelte";
|
||||
import Textarea from "@app/components/Textarea.svelte";
|
||||
import { Issue } from "@app/lib/issue";
|
||||
import { canonicalize, formatNodeId, parseNodeId } from "@app/lib/utils";
|
||||
import { formatNodeId, parseNodeId } from "@app/lib/utils";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
export let session: Session;
|
||||
@@ -19,13 +19,6 @@
|
||||
|
||||
const dispatch = createEventDispatcher<{ create: never }>();
|
||||
|
||||
// Get an image blob based on a relative path.
|
||||
const getImage = async (imagePath: string): Promise<MaybeBlob> => {
|
||||
const finalPath = canonicalize(imagePath, "/"); // We only use the root path in issues.
|
||||
const commit = project.branches[project.defaultBranch]; // We suppose that all issues are only looked at on HEAD of the default branch.
|
||||
return project.getBlob(commit, finalPath);
|
||||
};
|
||||
|
||||
let preview: boolean = false;
|
||||
|
||||
function handleAddAssignee() {
|
||||
@@ -181,14 +174,14 @@
|
||||
</div>
|
||||
<div class="comments">
|
||||
<Comment
|
||||
rawPath={project.getRawPath()}
|
||||
comment={{
|
||||
author: { id: session.publicKey },
|
||||
body: issueText,
|
||||
reactions: {},
|
||||
replyTo: null,
|
||||
timestamp: Date.now(),
|
||||
}}
|
||||
{getImage} />
|
||||
}} />
|
||||
</div>
|
||||
{:else}
|
||||
<Textarea bind:value={issueTitle} placeholder="Title" />
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<script lang="ts">
|
||||
import type * as proj from "@app/lib/project";
|
||||
import type { ProjectRoute } from "@app/lib/router/definitions";
|
||||
|
||||
import Markdown from "@app/components/Markdown.svelte";
|
||||
|
||||
export let content: string;
|
||||
export let getImage: (path: string) => Promise<proj.MaybeBlob>;
|
||||
export let rawPath: string;
|
||||
export let activeRoute: ProjectRoute;
|
||||
|
||||
$: path = activeRoute.params.path || "/";
|
||||
$: hash = activeRoute.params.hash || null;
|
||||
</script>
|
||||
|
||||
@@ -22,5 +22,5 @@
|
||||
</style>
|
||||
|
||||
<article>
|
||||
<Markdown {content} {getImage} {hash} />
|
||||
<Markdown {content} {hash} {rawPath} {path} />
|
||||
</article>
|
||||
|
||||
Reference in New Issue
Block a user