Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix templates upload #11

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { getS3DataTemplatesRoute } from "./routes/data/s3/templates.js";
import { getIPFSDataRoute } from "./routes/data/ipfs.js";

const DEV = process.env.NODE_ENV !== "production";
if (DEV) (await import("dotenv")).config();

const DISABLE_IPFS_PERSISTENCE =
process.env.DISABLE_IPFS_PERSISTENCE === "true";

const start = async () => {
if (DEV) (await import("dotenv")).config();

const HOST = requireEnv({ name: "HOST" });
const PORT = requireEnv({ name: "PORT" });
const server = createServer({
Expand Down
4 changes: 2 additions & 2 deletions src/routes/data/s3/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const getS3DataTemplatesRoute = async ({
allow: "multipart/form-data",
maxBytes: 5_000_000, // 5Mb
multipart: {
output: "stream",
output: "data",
},
parse: true,
timeout: 60000,
Expand All @@ -79,7 +79,7 @@ export const getS3DataTemplatesRoute = async ({
},
},
handler: async (request, h) => {
const template = request.payload as Record<string, Readable>;
const template = request.payload as Record<string, Buffer>;
for (let fileName of Object.keys(request.payload)) {
if (fileName === "/__car" || fileName === "__car") {
return badRequest(
Expand Down
15 changes: 5 additions & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,16 @@ export const ipfsEncodeJSON = async ({
};

interface DirectoryToCARParams {
directory: Record<string, Readable>;
directory: Record<string, Buffer>;
}

export const ipfsEncodeDirectory = async ({
directory,
}: DirectoryToCARParams): Promise<CARReturnValue> => {
const streamableFiles = Object.entries(directory).map<FileLike>(
([fileName, readable]) => {
return {
name: fileName,
stream: () => Readable.toWeb(readable),
};
},
);
const encodedDirectory = await UnixFS.encodeDirectory(streamableFiles);
const files = Object.entries(directory).map<File>(([fileName, buffer]) => {
return new File([buffer], fileName);
});
const encodedDirectory = await UnixFS.encodeDirectory(files);
const car = await CAR.encode(encodedDirectory.blocks, encodedDirectory.cid);
return { cid: encodedDirectory.cid.toString(), car };
};
Loading