Compare commits
No commits in common. "c0112d61fb749adc0cad6453a5162bd142aad88a" and "6c694d7d48d94d6f3c2c9cc9b7956f399a9162f9" have entirely different histories.
c0112d61fb
...
6c694d7d48
@ -165,14 +165,7 @@ const buildNeighborsQueryFilter = (filter = {}, search = '') => {
|
|||||||
return queryFilter;
|
return queryFilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getNeighborsCacheKey = ({
|
const getNeighborsCacheKey = ({ model, id, filter = {}, search = '', sort = '', order = 'ascend' }) => {
|
||||||
model,
|
|
||||||
id,
|
|
||||||
filter = {},
|
|
||||||
search = '',
|
|
||||||
sort = '',
|
|
||||||
order = 'ascend',
|
|
||||||
}) => {
|
|
||||||
const normalizedSort = sort || 'createdAt';
|
const normalizedSort = sort || 'createdAt';
|
||||||
const normalizedOrder = order || 'ascend';
|
const normalizedOrder = order || 'ascend';
|
||||||
const queryHash = crypto
|
const queryHash = crypto
|
||||||
@ -1193,7 +1186,11 @@ export async function getThumbnail({ fileId, size, file }) {
|
|||||||
const body = await downloadFile(BUCKETS.FILES, s3Key);
|
const body = await downloadFile(BUCKETS.FILES, s3Key);
|
||||||
const buffer = await streamToBuffer(body);
|
const buffer = await streamToBuffer(body);
|
||||||
|
|
||||||
await redisServer.setKey(cacheKey, buffer.toString('base64'), FILE_THUMBNAIL_CACHE_TTL_SECONDS);
|
await redisServer.setKey(
|
||||||
|
cacheKey,
|
||||||
|
buffer.toString('base64'),
|
||||||
|
FILE_THUMBNAIL_CACHE_TTL_SECONDS
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buffer,
|
buffer,
|
||||||
@ -1261,39 +1258,19 @@ async function deleteFileThumbnails(fileObject) {
|
|||||||
|
|
||||||
export async function createFileThumbnails(fileData, fileObject) {
|
export async function createFileThumbnails(fileData, fileObject) {
|
||||||
try {
|
try {
|
||||||
const extension = fileObject?.extension?.toLowerCase();
|
if (!fileObject?.type?.startsWith('image/') || !fileData || !fileObject?._id) {
|
||||||
const isGCodeFileType = extension === '.gcode' || extension === '.g';
|
|
||||||
const gcodeThumbnail = fileObject?.metaData?.thumbnail;
|
|
||||||
const hasGCodeThumbnailMeta =
|
|
||||||
isGCodeFileType && gcodeThumbnail && typeof gcodeThumbnail.data === 'string';
|
|
||||||
const isImageFileType = fileObject?.type?.startsWith('image/');
|
|
||||||
|
|
||||||
const hasThumbnailSource =
|
|
||||||
(hasGCodeThumbnailMeta && gcodeThumbnail.data.length > 0) ||
|
|
||||||
(isImageFileType && fileData);
|
|
||||||
|
|
||||||
if (!hasThumbnailSource || !fileObject?._id) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let thumbnailData = fileData;
|
|
||||||
if (hasGCodeThumbnailMeta) {
|
|
||||||
const normalized = gcodeThumbnail.data
|
|
||||||
.replace(/^data:image\/\w+;base64,/, '')
|
|
||||||
.replace(/\s/g, '');
|
|
||||||
thumbnailData = Buffer.from(normalized, 'base64');
|
|
||||||
if (!thumbnailData.length) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fileId = fileObject._id.toString();
|
const fileId = fileObject._id.toString();
|
||||||
const image = sharp(thumbnailData, { failOn: 'none' });
|
const image = sharp(fileData, { failOn: 'none' });
|
||||||
const imageMetadata = await image.metadata();
|
const imageMetadata = await image.metadata();
|
||||||
|
|
||||||
if (!imageMetadata.width || !imageMetadata.height) {
|
if (!imageMetadata.width || !imageMetadata.height) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blurhashSource = await sharp(thumbnailData)
|
const blurhashSource = await sharp(fileData)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(32, 32, { fit: 'inside' })
|
.resize(32, 32, { fit: 'inside' })
|
||||||
.ensureAlpha()
|
.ensureAlpha()
|
||||||
@ -1311,7 +1288,7 @@ export async function createFileThumbnails(fileData, fileObject) {
|
|||||||
const thumbnails = {};
|
const thumbnails = {};
|
||||||
|
|
||||||
for (const size of FILE_THUMBNAIL_SIZES) {
|
for (const size of FILE_THUMBNAIL_SIZES) {
|
||||||
const thumbnailBuffer = await sharp(thumbnailData)
|
const thumbnailBuffer = await sharp(fileData)
|
||||||
.rotate()
|
.rotate()
|
||||||
.resize(size, size, { fit: 'inside', withoutEnlargement: true })
|
.resize(size, size, { fit: 'inside', withoutEnlargement: true })
|
||||||
.jpeg({ quality: 85 })
|
.jpeg({ quality: 85 })
|
||||||
@ -1340,7 +1317,6 @@ export async function createFileThumbnails(fileData, fileObject) {
|
|||||||
metaData: {
|
metaData: {
|
||||||
...(fileObject.metaData || {}),
|
...(fileObject.metaData || {}),
|
||||||
blurHash,
|
blurHash,
|
||||||
thumbnails,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -145,8 +145,6 @@ export const slicerUploadRouteHandler = async (req, res) => {
|
|||||||
return res.status(createdFile.code || 500).send(createdFile);
|
return res.status(createdFile.code || 500).send(createdFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
createFileThumbnails(file.buffer, createdFile);
|
|
||||||
|
|
||||||
cephKey = `files/${createdFile._id}${extension}`;
|
cephKey = `files/${createdFile._id}${extension}`;
|
||||||
await uploadFile(BUCKETS.FILES, cephKey, file.buffer, contentType, {
|
await uploadFile(BUCKETS.FILES, cephKey, file.buffer, contentType, {
|
||||||
originalName,
|
originalName,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user