Skip to content

Commit ed668f7

Browse files
committed
fix: topic
1 parent 631db26 commit ed668f7

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

web/netlify.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ YARN_ENABLE_GLOBAL_CACHE = "true"
99

1010
[functions]
1111
directory = "web/netlify/functions/"
12+
13+
[dev]
14+
framework = "parcel"

web/netlify/functions/uploadToIPFS.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ type FormElement =
1111
| { isFile: false; content: string };
1212
type FormData = { [key: string]: FormElement };
1313

14-
const emitRabbitMQLog = async (cid: string) => {
14+
const emitRabbitMQLog = async (cid: string, operation: string) => {
1515
let connection: Connection | undefined;
1616
try {
1717
connection = await amqp.connect(RABBITMQ_URL ?? "");
1818
const channel = await connection.createChannel();
1919

20-
await channel.assertExchange("ipfs", "fanout", { durable: false });
21-
channel.publish("ipfs", "", Buffer.from(cid));
20+
await channel.assertExchange("ipfs", "topic");
21+
channel.publish("ipfs", operation, Buffer.from(cid));
2222

2323
//eslint-disable-next-line no-console
2424
console.log(`Sent IPFS CID '${cid}' to exchange 'ipfs'`);
@@ -50,7 +50,7 @@ const parseMultipart = ({ headers, body, isBase64Encoded }) =>
5050
bb.end();
5151
});
5252

53-
const pinToFilebase = async (data: FormData, dapp: string) => {
53+
const pinToFilebase = async (data: FormData, dapp: string, operation: string) => {
5454
const today = new Date();
5555
const year = today.getFullYear();
5656
const month = today.getMonth() + 1; // getMonth() is zero-based
@@ -65,7 +65,7 @@ const pinToFilebase = async (data: FormData, dapp: string) => {
6565

6666
const cid = await filebase.storeDirectory([new File([content], path, { type: mimeType })]);
6767

68-
await emitRabbitMQLog(cid);
68+
await emitRabbitMQLog(cid, operation);
6969
cids.push(cid);
7070
}
7171
}
@@ -76,14 +76,19 @@ const pinToFilebase = async (data: FormData, dapp: string) => {
7676
export const handler: Handler = async (event) => {
7777
const { queryStringParameters } = event;
7878

79-
if (!queryStringParameters || !queryStringParameters.dapp || !queryStringParameters.key) {
79+
if (
80+
!queryStringParameters ||
81+
!queryStringParameters.dapp ||
82+
!queryStringParameters.key ||
83+
!queryStringParameters.operation
84+
) {
8085
return {
8186
statusCode: 400,
8287
body: JSON.stringify({ message: "Invalid query parameters" }),
8388
};
8489
}
8590

86-
const { dapp, key } = queryStringParameters;
91+
const { dapp, key, operation } = queryStringParameters;
8792

8893
if (key !== FILEBASE_API_WRAPPER) {
8994
return {
@@ -94,7 +99,7 @@ export const handler: Handler = async (event) => {
9499

95100
try {
96101
const parsed = await parseMultipart(event);
97-
const cids = await pinToFilebase(parsed, dapp);
102+
const cids = await pinToFilebase(parsed, dapp, operation);
98103

99104
return {
100105
statusCode: 200,

0 commit comments

Comments
 (0)