nbd-wtf / nostr-tools

Tools for developing Nostr clients.
The Unlicense
709 stars 197 forks source link

[NIP-96] `validateFileUploadResponse` considers an empty `message` string as an invalid response #454

Open eyemono-moe opened 2 weeks ago

eyemono-moe commented 2 weeks ago

When the message in the response object is an empty string, validateFileUploadResponse treats it as an invalid response. This is because !response.message is used in the if statement.

https://github.com/nbd-wtf/nostr-tools/blob/bf0c4d4988a31670e788b200e787c51d20900868/nip96.ts#L272-L274

Some file storage servers (e.g., https://github.com/quentintaranpino/nostrcheck-server) return an empty message, which results in responses from such file storage servers being considered invalid. Is this the intended behavior?

reproduction

import { validateFileUploadResponse } from "nostr-tools/nip96";

const valid = validateFileUploadResponse({
  status: "success",
  message: "not empty",
  nip94_event: {
    tags: [
      ["url", "https://example.com/test.webp"],
      ["ox", "..."],
    ],
  },
});
console.log(valid); // -> true

const invalid = validateFileUploadResponse({
  status: "success",
  message: "", // empty
  nip94_event: {
    tags: [
      ["url", "https://example.com/test.webp"],
      ["ox", "..."],
    ],
  },
});
console.log(invalid); // -> false
AsaiToshiya commented 2 weeks ago

Probably, I think it seems necessary to compare to undefined not as falsy value.