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

BC-7899 Remove thumbnail related code in legacy files services. #5210

Merged
merged 6 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 0 additions & 4 deletions config/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ const globals = {
TEST_PW: (process.env.TEST_PW || '').trim(),
TEST_HASH: (process.env.TEST_HASH || '').trim(),

// files
FILE_PREVIEW_SERVICE_URI: process.env.FILE_PREVIEW_SERVICE_URI || 'http://localhost:3000/filepreview',
FILE_PREVIEW_CALLBACK_URI: process.env.FILE_PREVIEW_CALLBACK_URI || 'http://localhost:3030/fileStorage/thumbnail/',
ENABLE_THUMBNAIL_GENERATION: process.env.ENABLE_THUMBNAIL_GENERATION || false,
/** path must start and end with a slash */
SECURITY_CHECK_SERVICE_PATH: '/v1/fileStorage/securityCheck/',
FILE_SECURITY_CHECK_MAX_FILE_SIZE:
Expand Down
10 changes: 3 additions & 7 deletions src/services/fileStorage/docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,11 @@ module.exports = {
description: 'Returns the data signed url and meta properties',
example: {
signedUrl: {
url:
'https://<url>:<port>/bucket-5f2987e020834114b8efd6f8/1561200908775-24-1.gif?Content-Type=image%2Fgif&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sc-devteam%2F20190622%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20190622T105509Z&X-Amz-Expires=60&X-Amz-Signature=b098d101dea55fc3a8fa1e9accf4c99807e96ab22a91f3ee162e86c850e6a164&X-Amz-SignedHeaders=host',
url: 'https://<url>:<port>/bucket-5f2987e020834114b8efd6f8/1561200908775-24-1.gif?Content-Type=image%2Fgif&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sc-devteam%2F20190622%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20190622T105509Z&X-Amz-Expires=60&X-Amz-Signature=b098d101dea55fc3a8fa1e9accf4c99807e96ab22a91f3ee162e86c850e6a164&X-Amz-SignedHeaders=host',
header: {
'Content-Type': 'image/gif',
'x-amz-meta-name': '24-1.gif',
'x-amz-meta-flat-name': '1561200908775-24-1.gif',
'x-amz-meta-thumbnail': 'https://schulcloud.org/images/login-right.png',
},
},
},
Expand Down Expand Up @@ -546,8 +544,7 @@ module.exports = {
description: 'Returns the data with the signed url',
example: {
signedUrl: {
url:
'https://<url>:<port>/bucket-5f2987e020834114b8efd6f8/1561200908775-24-1.gif?Content-Type=image%2Fgif&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sc-devteam%2F20190622%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20190622T105509Z&X-Amz-Expires=60&X-Amz-Signature=b098d101dea55fc3a8fa1e9accf4c99807e96ab22a91f3ee162e86c850e6a164&X-Amz-SignedHeaders=host',
url: 'https://<url>:<port>/bucket-5f2987e020834114b8efd6f8/1561200908775-24-1.gif?Content-Type=image%2Fgif&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sc-devteam%2F20190622%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20190622T105509Z&X-Amz-Expires=60&X-Amz-Signature=b098d101dea55fc3a8fa1e9accf4c99807e96ab22a91f3ee162e86c850e6a164&X-Amz-SignedHeaders=host',
},
},
},
Expand Down Expand Up @@ -578,8 +575,7 @@ module.exports = {
description: 'Returns the data with the signed url',
example: {
signedUrl: {
url:
'https://<url>:<port>/bucket-5f2987e020834114b8efd6f8/1561200908775-24-1.gif?Content-Type=image%2Fgif&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sc-devteam%2F20190622%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20190622T105509Z&X-Amz-Expires=60&X-Amz-Signature=b098d101dea55fc3a8fa1e9accf4c99807e96ab22a91f3ee162e86c850e6a164&X-Amz-SignedHeaders=host',
url: 'https://<url>:<port>/bucket-5f2987e020834114b8efd6f8/1561200908775-24-1.gif?Content-Type=image%2Fgif&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=sc-devteam%2F20190622%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20190622T105509Z&X-Amz-Expires=60&X-Amz-Signature=b098d101dea55fc3a8fa1e9accf4c99807e96ab22a91f3ee162e86c850e6a164&X-Amz-SignedHeaders=host',
},
},
},
Expand Down
33 changes: 0 additions & 33 deletions src/services/fileStorage/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -977,39 +977,6 @@ paths:
tags:
- files
security: []
'/fileStorage/thumbnail/{id}':
patch:
parameters:
- in: path
name: id
description: ID of thumbnail to update
schema:
type: integer
required: true
responses:
'200':
description: success
content:
application/json:
schema:
$ref: '#/components/schemas/thumbnail'
'401':
description: not authenticated
'404':
description: not found
'500':
description: general error
description: Updates the resource identified by id using data.
summary: ''
tags:
- fileStorage
security: []
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/thumbnail'
'/fileStorage/securityCheck/{id}':
put:
parameters:
Expand Down
61 changes: 3 additions & 58 deletions src/services/fileStorage/proxy-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const { userModel } = require('../user/model');
const logger = require('../../logger');
const { equal: equalIds } = require('../../helper/compare').ObjectId;
const {
FILE_PREVIEW_SERVICE_URI,
FILE_PREVIEW_CALLBACK_URI,
FILE_SECURITY_CHECK_MAX_FILE_SIZE,
SECURITY_CHECK_SERVICE_PATH,
} = require('../../../config/globals');
Expand Down Expand Up @@ -80,58 +78,6 @@ const getStorageProviderIdAndBucket = async (userId, fileObject, strategy) => {
};
};

const prepareThumbnailGeneration = async (
file,
strategy,
userId,
{ name: dataName },
{ storageFileName, name: propName }
) => {
if (Configuration.get('ENABLE_THUMBNAIL_GENERATION') === true) {
const fileObject = await FileModel.findOne({ _id: file }).lean().exec();

if (!fileObject) {
throw new NotFound('File seems not to be there.');
}

const { storageProviderId, bucket } = await getStorageProviderIdAndBucket(userId, fileObject);

Promise.all([
strategy.getSignedUrl({
storageProviderId,
bucket,
flatFileName: storageFileName,
localFileName: storageFileName,
download: true,
Expires: 3600 * 24,
}),
strategy.generateSignedUrl({
userId,
flatFileName: storageFileName.replace(/(\..+)$/, '-thumbnail.png'),
fileType: returnFileType(dataName || propName), // data.type
}),
]).then(([downloadUrl, signedS3Url]) =>
rp
.post({
url: FILE_PREVIEW_SERVICE_URI,
body: {
downloadUrl,
signedS3Url,
callbackUrl: url.resolve(FILE_PREVIEW_CALLBACK_URI, file.thumbnailRequestToken),
options: {
width: 120,
},
},
json: true,
})
.catch((err) => {
logger.warning(new Error('Can not create tumbnail', err)); // todo err message is lost and throw error
})
);
}
return Promise.resolve();
};

/**
*
* @param {File} file the file object
Expand Down Expand Up @@ -267,7 +213,7 @@ const fileStorageService = {
if (!file) file = await FileModel.create(props);

prepareSecurityCheck(file, creatorId, strategy).catch(asyncErrorHandler);
prepareThumbnailGeneration(file, strategy, creatorId, data, props).catch(asyncErrorHandler);

return file;
},

Expand Down Expand Up @@ -434,7 +380,7 @@ const signedUrlService = {
const header = {
name: encodeURIComponent(filename),
'flat-name': encodeURIComponent(flatFileName),
thumbnail: 'https://schulcloud.org/images/login-right.png',
thumbnail: '',
};

return parentPromise
Expand All @@ -457,7 +403,6 @@ const signedUrlService = {
'Content-Type': fileType,
'x-amz-meta-name': header.name,
'x-amz-meta-flat-name': header['flat-name'],
'x-amz-meta-thumbnail': header.thumbnail,
},
}))
.catch((err) => {
Expand Down Expand Up @@ -836,7 +781,7 @@ const newFileService = {
size: buffer.length,
storageFileName: flatFileName,
type: returnFileType(name),
thumbnail: 'https://schulcloud.org/images/login-right.png',
thumbnail: '',
name,
owner,
parent,
Expand Down
26 changes: 0 additions & 26 deletions src/services/fileStorage/thumbnail-service.js

This file was deleted.

4 changes: 0 additions & 4 deletions test/services/fileStorage/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,6 @@ describe('fileStorage services', () => {
});
});

it('registered the thumbnail service', () => {
assert.ok(app.service('fileStorage/thumbnail'));
});

describe('directory service', () => {
it('registered the directory service', () => {
assert.ok(app.service('fileStorage/directories'));
Expand Down
Loading