Skip to content

Commit 91919ce

Browse files
committed
Fix broken media upload on home page
1 parent 3dde7dd commit 91919ce

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.changeset/cool-coins-sort.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"blossom-server-ts": patch
3+
---
4+
5+
Fix broken media upload on home page

public/upload-form.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ export class UploadForm extends LitElement {
3838

3939
this.status = "Signing...";
4040

41+
const endpoint = this.optimize ? "/media" : "/upload";
42+
4143
// create auth event
4244
const auth = await window.nostr.signEvent({
4345
kind: 24242,
4446
content: "Authorize Upload",
4547
created_at: unixNow(),
4648
tags: [
47-
["t", "upload"],
49+
["t", optimize ? "media" : "upload"],
4850
["x", hash],
4951
["expiration", newExpirationValue()],
5052
],
@@ -53,7 +55,7 @@ export class UploadForm extends LitElement {
5355

5456
// BUD-06 check upload
5557
this.status = "Checking Upload...";
56-
const check = await fetch("/upload", {
58+
const check = await fetch(endpoint, {
5759
method: "HEAD",
5860
headers: {
5961
authorization,
@@ -69,7 +71,7 @@ export class UploadForm extends LitElement {
6971

7072
// Upload blob
7173
this.status = "Uploading...";
72-
const res = await fetch(this.optimize ? "/media" : "/upload", {
74+
const res = await fetch(endpoint, {
7375
method: "PUT",
7476
body: file,
7577
// attach Authorization: Nostr <base64> header to request

src/api/upload.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function checkUpload(
2424
// check auth
2525
if (opts.requireAuth) {
2626
if (!ctx.state.auth) throw new HttpErrors.Unauthorized("Missing Auth event");
27-
if (ctx.state.authType !== authType) throw new HttpErrors.Unauthorized("Auth event must be 'upload'");
27+
if (ctx.state.authType !== authType) throw new HttpErrors.Unauthorized(`Auth event must be '${authType}'`);
2828
if (hasUsedToken(ctx.state.auth.id)) throw new HttpErrors.BadRequest("Auth event already used");
2929

3030
// BUD-06, check if hash is in auth event

0 commit comments

Comments
 (0)