Skip to content

Commit

Permalink
fix: preview
Browse files Browse the repository at this point in the history
  • Loading branch information
annahassel committed Apr 5, 2024
1 parent 9c23598 commit ae656fb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/custom/cappasity-info-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,9 @@ const GREEN_LIGHT_STATUSES = Object.setPrototypeOf({
module.exports = async function getEmbeddedInfo(file) {
if (file.uploadType === UPLOAD_TYPE_CLOUDFLARE_STREAM) {
const cloudflareStream = this.providersByAlias['cloudflare-stream'];
const filename = file.files[0]?.filename;

if (cloudflareStream && filename) {
file.preview = await cloudflareStream.getThumbnailUrlSigned(filename);
if (cloudflareStream && file.preview) {
file.preview = await cloudflareStream.getThumbnailUrlSigned(file.preview);
}

return file;
Expand Down
10 changes: 9 additions & 1 deletion src/custom/cappasity-process-pre.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
const Promise = require('bluebird');
const { HttpStatusError } = require('common-errors');
const debug = require('debug')('process-pre');
const { FILES_OWNER_FIELD, CAPPASITY_TYPE_MAP } = require('../constant');
const {
CAPPASITY_TYPE_MAP,
FILES_OWNER_FIELD,
UPLOAD_TYPE_CLOUDFLARE_STREAM,
} = require('../constant');

function parseMeta(data) {
const parsedFiles = typeof data.files === 'string' ? JSON.parse(data.files) : data.files;
const output = Object.create(null);

let textures = 0;
parsedFiles.forEach(({ type, filename }) => {
if (data.uploadType === UPLOAD_TYPE_CLOUDFLARE_STREAM && type === 'video' && !output.preview) {
output.preview = filename;
}

const responsibility = CAPPASITY_TYPE_MAP[type];

/** skip for simple uploads */
Expand Down
11 changes: 11 additions & 0 deletions test/suites/upload.cloudflare-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ dotenv.config({ path: path.resolve(__dirname, '../.env') });

function overrideConfig() {
this.configOverride = {
hooks: {
'files:upload:pre': [],
// eslint-disable-next-line import/no-dynamic-require
'files:process:pre': require(`${process.cwd()}/src/custom/cappasity-process-pre`),
'files:process:post': [],
'files:info:pre': (alias) => alias,
'files:update:pre': [],
'files:download:alias': (username) => username,
// eslint-disable-next-line import/no-dynamic-require
'files:info:post': require(`${process.cwd()}/src/custom/cappasity-info-post`),
},
selectTransport: require('../../src/custom/cappasity-select-bucket'),
transport: [{
name: 'gce',
Expand Down

0 comments on commit ae656fb

Please sign in to comment.