@elumixor/notion-orm 2.2.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +27 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1619,6 +1619,26 @@ function recursivelyBuildFilter(queryFilter, camelPropertyNameToNameAndTypeMap)
1619
1619
  }
1620
1620
 
1621
1621
  // src/db-client/client.ts
1622
+ var MIME_TO_EXT = {
1623
+ "image/jpeg": "jpg",
1624
+ "image/png": "png",
1625
+ "image/gif": "gif",
1626
+ "image/webp": "webp",
1627
+ "image/svg+xml": "svg",
1628
+ "image/avif": "avif"
1629
+ };
1630
+ function sniffMimeType(bytes) {
1631
+ if (bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255)
1632
+ return "image/jpeg";
1633
+ if (bytes[0] === 137 && bytes[1] === 80 && bytes[2] === 78 && bytes[3] === 71)
1634
+ return "image/png";
1635
+ if (bytes[0] === 71 && bytes[1] === 73 && bytes[2] === 70)
1636
+ return "image/gif";
1637
+ if (bytes[8] === 87 && bytes[9] === 69 && bytes[10] === 66 && bytes[11] === 80)
1638
+ return "image/webp";
1639
+ return "application/octet-stream";
1640
+ }
1641
+
1622
1642
  class DatabaseClient {
1623
1643
  client;
1624
1644
  id;
@@ -1759,9 +1779,13 @@ class DatabaseClient {
1759
1779
  return null;
1760
1780
  if (typeof value === "string")
1761
1781
  return { type: "external", external: { url: value } };
1762
- const blob = value instanceof Blob ? value : new Blob([value]);
1763
- const upload = await this.client.fileUploads.create({ filename: "upload" });
1764
- await this.client.fileUploads.send({ file_upload_id: upload.id, file: { data: blob, filename: "upload" } });
1782
+ const bytes = value instanceof Blob ? new Uint8Array(await value.arrayBuffer()) : value;
1783
+ const contentType = value instanceof Blob && value.type ? value.type : sniffMimeType(bytes);
1784
+ const ext = MIME_TO_EXT[contentType] ?? "bin";
1785
+ const filename = `upload.${ext}`;
1786
+ const blob = new Blob([bytes], { type: contentType });
1787
+ const upload = await this.client.fileUploads.create({ filename, content_type: contentType });
1788
+ await this.client.fileUploads.send({ file_upload_id: upload.id, file: { data: blob, filename } });
1765
1789
  return { type: "file_upload", file_upload: { id: upload.id } };
1766
1790
  }
1767
1791
  parsePage(page, meta) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elumixor/notion-orm",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "type": "module",
5
5
  "description": "Bring Notion database schemas/types to TypeScript",
6
6
  "main": "dist/index.js",