mirror of
https://github.com/logos-storage/logos-storage-js.git
synced 2026-01-08 00:13:06 +00:00
Fix minor issues
This commit is contained in:
parent
7e1b0792d3
commit
19d798e7dc
@ -9,7 +9,7 @@
|
||||
"scripts": {
|
||||
"prepack": "tsup tsup src/index.ts --format esm,cjs --dts",
|
||||
"prebuild": "rm -Rf dist/*",
|
||||
"build": "tsc --p tsconfig.test.json",
|
||||
"build": "tsc --p tsconfig.json",
|
||||
"compile": "tsc --noEmit",
|
||||
"pretest": "npm run build",
|
||||
"pretest:only": "npm run build",
|
||||
|
||||
@ -3,12 +3,12 @@ import { Fetch } from "../fetch-safe/fetch-safe";
|
||||
import type { SafeValue } from "../values/values";
|
||||
import type { CodexDataResponse, CodexNodeSpace } from "./types";
|
||||
|
||||
type UploadResponse = {
|
||||
export type UploadResponse = {
|
||||
result: Promise<SafeValue<string>>;
|
||||
abort: () => void;
|
||||
};
|
||||
|
||||
export class Data {
|
||||
export class CodexData {
|
||||
readonly url: string;
|
||||
|
||||
constructor(url: string) {
|
||||
@ -29,39 +29,10 @@ export class Data {
|
||||
return data;
|
||||
}
|
||||
|
||||
const mimetypes = [
|
||||
"image/png",
|
||||
"image/jpg",
|
||||
"image/jpeg",
|
||||
"audio/mp3",
|
||||
"video/mp4",
|
||||
"application/pdf",
|
||||
"application/msdoc",
|
||||
"text/plain",
|
||||
];
|
||||
|
||||
return {
|
||||
error: false,
|
||||
data: {
|
||||
content: data.data.content.map((content) => {
|
||||
const random = Math.trunc(Math.random() * (mimetypes.length - 1));
|
||||
const mimetype = mimetypes[random];
|
||||
const [, extension] = mimetype?.split("/") || [];
|
||||
const filename = Array(5)
|
||||
.fill("")
|
||||
.map((_) => ((Math.random() * 36) | 0).toString(36))
|
||||
.join("");
|
||||
|
||||
return {
|
||||
cid: content.cid,
|
||||
manifest: {
|
||||
...content.manifest,
|
||||
filename: `${filename}.${extension}`,
|
||||
mimetype: mimetype || "",
|
||||
uploadedAt: new Date().toJSON(),
|
||||
},
|
||||
};
|
||||
}),
|
||||
content: data.data.content,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { Data } from "./data/data";
|
||||
import type { CodexData } from "./data/data";
|
||||
import type { Node } from "./node/node";
|
||||
import { Marketplace } from "./marketplace/marketplace";
|
||||
import type { Debug } from "./debug/debug";
|
||||
@ -10,10 +10,12 @@ export * from "./data/types";
|
||||
export * from "./values/values";
|
||||
export * from "./errors/errors";
|
||||
|
||||
export { type CodexData, type UploadResponse } from "./data/data";
|
||||
|
||||
export class Codex {
|
||||
readonly url: string;
|
||||
private _marketplace: Marketplace | null;
|
||||
private _data: Data | null;
|
||||
private _data: CodexData | null;
|
||||
private _node: Node | null;
|
||||
private _debug: Debug | null;
|
||||
|
||||
@ -44,7 +46,7 @@ export class Codex {
|
||||
|
||||
const module = await import("./data/data");
|
||||
|
||||
this._data = new module.Data(this.url);
|
||||
this._data = new module.CodexData(this.url);
|
||||
|
||||
return this._data;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user