-
Notifications
You must be signed in to change notification settings - Fork 6
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
Apply blurhash to all existing images #214
Comments
@madaxen86 that does indeed sound like a nice addition. Do you have a suggestion as to how this could be triggered? Some custom button in the UI somewhere perhaps? I am not sure whether it's a good idea to do this on app startup, maybe at least it'd have to be opt-in. |
I played around a little bit yesterday. Adding this to const computeBlurhash = (pluginOptions?: BlurhashPluginOptions) => {
//...
return {
...incomingConfig,
collections: {
//...
},
onInit: async (payload) => {
// execute existing onInit
if (incomingConfig.onInit) await incomingConfig.onInit(payload);
if (!pluginOptions.addBlurhashToExistingOnInit) return;
const rehash = async (collection: string) => {
const images = await payload.find({
collection: collection as any,
pagination: false,
where: {
blurhash: {
equals: null,
},
},
});
const staticDir = path.resolve(__dirname, payload.collections[collection].config.upload.staticDir);
images.docs.forEach(async (image) => {
try {
await payload.update({
collection: collection as any,
id: image.id,
data: image,
filePath: `${staticDir}/${image.filename}`,
overwriteExistingFiles: true,
});
} catch (error) {
console.error("#####", error.message, image.id, image.mimeType);
}
});
};
Object.entries(payload.collections).forEach(async ([key, value]) => {
if (value.config?.upload && (!collections || collections.includes(key)) ) {
await rehash(key);
}
});
},
};
};
|
Note: This will also trigger Image transformations for all the images without an existing blurhash. |
@invakid404 did you have a chance to have a look at this and test it? |
@madaxen86 I am looking into it. I would need to support remote storage as well, as there was a feature request for that at one point, so it's important. |
Little edit: for querying the docs, |
It would be nice to have an option to apply the blurhash to all images where blurhash is null when the app starts.
That would be very useful when the plugin is added to an existing project where images have already been uploaded.
The text was updated successfully, but these errors were encountered: