mediaController: get cid, fix permissions, host on /ipfs
This commit is contained in:
parent
3fc60c78d2
commit
4622b52f78
|
@ -1,6 +1,6 @@
|
||||||
import { AppController } from '@/app.ts';
|
import { AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { S3Client, z } from '@/deps.ts';
|
import { IpfsHash, S3Client, z } from '@/deps.ts';
|
||||||
import { fileSchema } from '@/schema.ts';
|
import { fileSchema } from '@/schema.ts';
|
||||||
import { parseBody } from '@/utils/web.ts';
|
import { parseBody } from '@/utils/web.ts';
|
||||||
|
|
||||||
|
@ -21,15 +21,24 @@ const mediaController: AppController = async (c) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { file } = result.data;
|
const { file } = result.data;
|
||||||
|
const cid = await IpfsHash.of(file.stream()) as string;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await s3.putObject('test', file.stream());
|
await s3.putObject(`ipfs/${cid}`, file.stream(), {
|
||||||
|
metadata: {
|
||||||
|
'Content-Type': file.type,
|
||||||
|
'x-amz-acl': 'public-read',
|
||||||
|
},
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return c.json({ error: 'Failed to upload file.' }, 500);
|
return c.json({ error: 'Failed to upload file.' }, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.json({});
|
return c.json({
|
||||||
|
id: cid,
|
||||||
|
type: file.type,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export { mediaController };
|
export { mediaController };
|
||||||
|
|
|
@ -67,5 +67,6 @@ export { DenoSqliteDialect } from 'https://gitlab.com/soapbox-pub/kysely-deno-sq
|
||||||
export { default as tldts } from 'npm:tldts@^6.0.14';
|
export { default as tldts } from 'npm:tldts@^6.0.14';
|
||||||
export * as cron from 'https://deno.land/x/deno_cron@v1.0.0/cron.ts';
|
export * as cron from 'https://deno.land/x/deno_cron@v1.0.0/cron.ts';
|
||||||
export { S3Client } from 'https://deno.land/x/s3_lite_client@0.6.1/mod.ts';
|
export { S3Client } from 'https://deno.land/x/s3_lite_client@0.6.1/mod.ts';
|
||||||
|
export { default as IpfsHash } from 'npm:ipfs-only-hash@^4.0.0';
|
||||||
|
|
||||||
export type * as TypeFest from 'npm:type-fest@^4.3.0';
|
export type * as TypeFest from 'npm:type-fest@^4.3.0';
|
||||||
|
|
Loading…
Reference in New Issue