Merge pull request #1303 from PicPeak/fix/1300-remove-fragmentation
fix: remove the image-fragmentation surface
This commit is contained in:
@@ -175,8 +175,7 @@ class SecureImageService {
|
||||
quality = 85,
|
||||
maxWidth = 1920,
|
||||
maxHeight = 1080,
|
||||
addFingerprint = true,
|
||||
fragmentImage = false
|
||||
addFingerprint = true
|
||||
} = options;
|
||||
|
||||
try {
|
||||
@@ -187,7 +186,7 @@ class SecureImageService {
|
||||
|
||||
// For standard protection without fingerprinting, return original file
|
||||
// This avoids unnecessary recompression when no protection features are needed
|
||||
if (protectionLevel === 'standard' && !addFingerprint && !fragmentImage) {
|
||||
if (protectionLevel === 'standard' && !addFingerprint) {
|
||||
return await fs.readFile(imagePath);
|
||||
}
|
||||
|
||||
@@ -268,14 +267,7 @@ class SecureImageService {
|
||||
});
|
||||
}
|
||||
|
||||
const buffer = await image.toBuffer();
|
||||
|
||||
// Fragment image if requested (for canvas reconstruction)
|
||||
if (fragmentImage && protectionLevel === 'maximum') {
|
||||
return await this.fragmentImageBuffer(buffer, metadata);
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return await image.toBuffer();
|
||||
} catch (error) {
|
||||
logger.error('Error processing protected image:', error);
|
||||
// Return original on error
|
||||
@@ -283,51 +275,6 @@ class SecureImageService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment image into multiple pieces for canvas reconstruction
|
||||
*/
|
||||
async fragmentImageBuffer(buffer, metadata) {
|
||||
const { width, height } = metadata;
|
||||
const fragments = [];
|
||||
|
||||
// Create 3x3 grid of fragments
|
||||
const cols = 3;
|
||||
const rows = 3;
|
||||
const fragmentWidth = Math.floor(width / cols);
|
||||
const fragmentHeight = Math.floor(height / rows);
|
||||
|
||||
for (let row = 0; row < rows; row++) {
|
||||
for (let col = 0; col < cols; col++) {
|
||||
const left = col * fragmentWidth;
|
||||
const top = row * fragmentHeight;
|
||||
|
||||
const fragment = await sharp(buffer)
|
||||
.extract({
|
||||
left,
|
||||
top,
|
||||
width: fragmentWidth,
|
||||
height: fragmentHeight
|
||||
})
|
||||
.toBuffer();
|
||||
|
||||
fragments.push({
|
||||
index: row * cols + col,
|
||||
row,
|
||||
col,
|
||||
buffer: fragment,
|
||||
position: { left, top, width: fragmentWidth, height: fragmentHeight }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'fragmented',
|
||||
fragments,
|
||||
originalDimensions: { width, height },
|
||||
fragmentDimensions: { width: fragmentWidth, height: fragmentHeight, cols, rows }
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Log image access for security monitoring
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user