-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'restrict-file-access' into hardcore-refactor
- Loading branch information
Showing
24 changed files
with
510 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { File as FileType } from '@unchainedshop/core-files'; | ||
import { File as FileType, getFileAdapter } from '@unchainedshop/core-files'; | ||
import { Context } from '../../context.js'; | ||
|
||
import { checkAction } from '../../acl.js'; | ||
import { actions } from '../../roles/index.js'; | ||
export interface MediaHelperTypes { | ||
url: (language: FileType, params: Record<string, any>, context: Context) => string; | ||
url: (language: FileType, params: Record<string, any>, context: Context) => Promise<string>; | ||
} | ||
|
||
export const Media: MediaHelperTypes = { | ||
url(root, params, { modules }) { | ||
return modules.files.getUrl(root, params); | ||
url: async (file, params, context) => { | ||
const { modules } = context; | ||
try { | ||
await checkAction(context, actions.downloadFile, [file, params]); | ||
if (!file) return null; | ||
const fileUploadAdapter = getFileAdapter(); | ||
const url = await fileUploadAdapter.createDownloadURL(file, params?.expires); | ||
return modules.files.normalizeUrl(url, params); | ||
} catch (e) { | ||
console.error(e); | ||
return null; | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
export interface FilesSettingsOptions { | ||
transformUrl?: (url: string, params: Record<string, any>) => string; | ||
privateFileSharingMaxAge?: number; | ||
} | ||
|
||
export interface FilesSettings { | ||
transformUrl?: (url: string, params: Record<string, any>) => string; | ||
configureSettings: (options?: FilesSettingsOptions) => void; | ||
privateFileSharingMaxAge?: number; | ||
} | ||
|
||
export const defaultTransformUrl = (url) => url; | ||
|
||
export const filesSettings: FilesSettings = { | ||
transformUrl: null, | ||
configureSettings: async ({ transformUrl }) => { | ||
privateFileSharingMaxAge: null, | ||
configureSettings: async ({ transformUrl, privateFileSharingMaxAge }) => { | ||
filesSettings.transformUrl = transformUrl || defaultTransformUrl; | ||
filesSettings.privateFileSharingMaxAge = privateFileSharingMaxAge; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,22 @@ | ||
import { UnchainedCore } from '@unchainedshop/core'; | ||
import { FileDirector } from '@unchainedshop/file-upload'; | ||
|
||
export const setupUploadHandlers = () => { | ||
FileDirector.registerFileUploadCallback<UnchainedCore>('user-avatars', async (file, context) => { | ||
const { services } = context; | ||
export const setupUploadHandlers = ({ services, modules }: UnchainedCore) => { | ||
FileDirector.registerFileUploadCallback('user-avatars', async (file) => { | ||
return services.users.updateUserAvatarAfterUpload({ file }); | ||
}); | ||
|
||
FileDirector.registerFileUploadCallback('product-media', async (file) => { | ||
await modules.products.media.create({ | ||
productId: file.meta?.productId as string, | ||
mediaId: file._id, | ||
}); | ||
}); | ||
|
||
FileDirector.registerFileUploadCallback('assortment-media', async (file) => { | ||
await modules.assortments.media.create({ | ||
assortmentId: file.meta.assortmentId as string, | ||
mediaId: file._id, | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.