Skip to content

Commit 53a9099

Browse files
committed
Fix typo in /mirror endpoint
1 parent ed1904d commit 53a9099

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

.changeset/shy-months-drum.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"blossom-server-ts": patch
3+
---
4+
5+
Fix typo in /mirror endpoint

.github/workflows/version-or-publish.yml

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
- name: Install Dependencies
3636
run: pnpm install
3737

38+
- name: Install Dependencies
39+
run: pnpm build
40+
3841
- name: Create Release Pull Request or Publish to npm
3942
id: changesets
4043
uses: changesets/action@v1

public/mirror-blobs.js

+26-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { formatBytes, newExpirationValue, unixNow } from "./utils.js";
33

44
export class MirrorBlobs extends LitElement {
55
static properties = {
6+
showAll: { state: true, type: Boolean },
67
remoteBlobs: { state: true },
78
localBlobs: { state: true },
89

@@ -49,8 +50,7 @@ export class MirrorBlobs extends LitElement {
4950

5051
localAuth = null;
5152
async fetchLocalBlobs() {
52-
this.pubkey = await window.nostr?.getPublicKey();
53-
if (!this.pubkey) return;
53+
const pubkey = await window.nostr.getPublicKey();
5454

5555
this.status = "Signing...";
5656

@@ -67,7 +67,7 @@ export class MirrorBlobs extends LitElement {
6767

6868
this.status = "Fetching...";
6969

70-
this.localBlobs = await fetch("/list/" + this.pubkey, {
70+
this.localBlobs = await fetch("/list/" + pubkey, {
7171
headers: { authorization: "Nostr " + btoa(JSON.stringify(this.localAuth)) },
7272
}).then((res) => res.json());
7373

@@ -110,18 +110,27 @@ export class MirrorBlobs extends LitElement {
110110
</form>`;
111111
}
112112

113+
getShownBlobs() {
114+
return this.showAll
115+
? this.remoteBlobs
116+
: this.remoteBlobs.filter((blob) => !this.localBlobs.some((b) => b.sha256 === blob.sha256));
117+
}
118+
113119
selectAll() {
114-
const missingBlobs = this.remoteBlobs.filter((blob) => !this.localBlobs.some((b) => b.sha256 === blob.sha256));
120+
const blobs = this.getShownBlobs();
115121

116-
if (this.selected.length === missingBlobs.length) {
122+
if (this.selected.length === blobs.length) {
117123
this.selected = [];
118-
} else this.selected = missingBlobs.map((b) => b.sha256);
124+
} else this.selected = blobs.map((b) => b.sha256);
119125
}
120126
toggleSelection(sha256) {
121127
if (this.selected.includes(sha256)) {
122128
this.selected = this.selected.filter((s) => s !== sha256);
123129
} else this.selected = [...this.selected, sha256];
124130
}
131+
toggleShowAll() {
132+
this.showAll = !this.showAll;
133+
}
125134

126135
async mirrorBlobs() {
127136
const blobs = this.remoteBlobs.filter((blob) => this.selected.includes(blob.sha256));
@@ -170,10 +179,15 @@ export class MirrorBlobs extends LitElement {
170179
} else if (this.status) {
171180
return html`<p class="my-5 text-center text-lg">${this.status}</p>`;
172181
} else if (this.remoteBlobs && this.localBlobs) {
173-
const missingBlobs = this.remoteBlobs.filter((blob) => !this.localBlobs.some((b) => b.sha256 === blob.sha256));
174-
175-
if (missingBlobs.length === 0) {
176-
return html`<p class="text-green-500 text-lg text-center p-10">All blobs synced ✅</p>`;
182+
const blobs = this.getShownBlobs();
183+
const check = html` <label
184+
><input type="checkbox" type="checkbox" .checked="${this.showAll}" @change="${this.toggleShowAll}" /> Show
185+
all</label
186+
>`;
187+
188+
if (blobs.length === 0) {
189+
return html`${check}
190+
<p class="text-green-500 text-lg text-center p-10">All blobs synced ✅</p>`;
177191
}
178192

179193
return html`
@@ -184,14 +198,15 @@ export class MirrorBlobs extends LitElement {
184198
>
185199
Select All
186200
</button>
201+
${check}
187202
<button
188203
class="text-md bg-blue-500 text-gray-100 py-1 px-3 rounded-md tracking-wide font-semibold hover:bg-blue-600 cursor-pointer transition ease-in duration-300 flex-shrink-0 ml-auto"
189204
@click="${this.mirrorBlobs}"
190205
>
191206
Mirror Blobs
192207
</button>
193208
</div>
194-
${this.renderBlobs(missingBlobs)}
209+
${this.renderBlobs(blobs)}
195210
`;
196211
}
197212

src/api/mirror.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ router.put<CommonState>("/mirror", async (ctx) => {
7777
const upload = (maybeUpload = await saveFromResponse(response));
7878
const type = contentType || upload.type;
7979

80-
// check if auth has blob sha256 hash
81-
if (
82-
config.upload.requireAuth &&
83-
(!ctx.state.auth || ctx.state.auth.tags.some((t) => t[0] === "x" && t[1] === upload.sha256))
84-
)
85-
throw new HttpErrors.BadRequest("Auth missing blob sha256 hash");
80+
if (config.upload.requireAuth) {
81+
// check if auth has blob sha256 hash
82+
if (!ctx.state.auth?.tags.some((t) => t[0] === "x" && t[1] === upload.sha256))
83+
throw new HttpErrors.BadRequest("Auth missing blob sha256 hash");
84+
}
8685

8786
let blob: BlobMetadata;
8887

0 commit comments

Comments
 (0)