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

fix: add support for private upload providers #19863

Merged
merged 3 commits into from Mar 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -61,6 +61,30 @@ function getFileStats(filepath: string, isLocal = false): Promise<{ size: number
});
});
}

async function signUrl(isLocalProvider: boolean, file: any) {
if (isLocalProvider) return;
const { provider } = strapi.plugins.upload;
const { provider: providerName } = strapi.config.get('plugin.upload') as any;
const isPrivate = await provider.isPrivate();
if (file.provider === providerName && isPrivate) {
const signUrl = async (file: any) => {
Bassel17 marked this conversation as resolved.
Show resolved Hide resolved
const signedUrl = await provider.getSignedUrl(file);
file.url = signedUrl.url;
file.isUrlSigned = true;
};

// Sign the original file
await signUrl(file);
// Sign each file format
if (file.formats) {
for (const format of Object.keys(file.formats)) {
await signUrl(file.formats[format]);
}
}
}
}

/**
* Generate and consume assets streams in order to stream each file individually
*/
Expand All @@ -76,6 +100,7 @@ export const createAssetsStream = (strapi: LoadedStrapi): Duplex => {

for await (const file of stream) {
const isLocalProvider = file.provider === 'local';
await signUrl(isLocalProvider, file);
Bassel17 marked this conversation as resolved.
Show resolved Hide resolved
const filepath = isLocalProvider ? join(strapi.dirs.static.public, file.url) : file.url;
const stats = await getFileStats(filepath, isLocalProvider);
const stream = getFileStream(filepath, isLocalProvider);
Expand Down