@strapi/upload 5.20.0 → 5.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/hooks/useBulkRemove.js +5 -0
- package/dist/admin/hooks/useBulkRemove.js.map +1 -1
- package/dist/admin/hooks/useBulkRemove.mjs +6 -1
- package/dist/admin/hooks/useBulkRemove.mjs.map +1 -1
- package/dist/admin/hooks/useRemoveAsset.js +5 -0
- package/dist/admin/hooks/useRemoveAsset.js.map +1 -1
- package/dist/admin/hooks/useRemoveAsset.mjs +6 -1
- package/dist/admin/hooks/useRemoveAsset.mjs.map +1 -1
- package/dist/admin/hooks/useUpload.js +5 -0
- package/dist/admin/hooks/useUpload.js.map +1 -1
- package/dist/admin/hooks/useUpload.mjs +6 -1
- package/dist/admin/hooks/useUpload.mjs.map +1 -1
- package/dist/admin/package.json.js +6 -5
- package/dist/admin/package.json.js.map +1 -1
- package/dist/admin/package.json.mjs +6 -5
- package/dist/admin/package.json.mjs.map +1 -1
- package/package.json +6 -5
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var strapiAdmin = require('@strapi/admin/strapi-admin');
|
|
4
4
|
var reactIntl = require('react-intl');
|
|
5
5
|
var reactQuery = require('react-query');
|
|
6
|
+
var reactRedux = require('react-redux');
|
|
6
7
|
var pluginId = require('../pluginId.js');
|
|
7
8
|
require('byte-size');
|
|
8
9
|
require('date-fns');
|
|
@@ -12,6 +13,7 @@ require('../constants.js');
|
|
|
12
13
|
require('../utils/urlYupSchema.js');
|
|
13
14
|
|
|
14
15
|
const useBulkRemove = ()=>{
|
|
16
|
+
const dispatch = reactRedux.useDispatch();
|
|
15
17
|
const { toggleNotification } = strapiAdmin.useNotification();
|
|
16
18
|
const { formatMessage } = reactIntl.useIntl();
|
|
17
19
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -60,6 +62,9 @@ const useBulkRemove = ()=>{
|
|
|
60
62
|
defaultMessage: 'Elements have been successfully deleted.'
|
|
61
63
|
})
|
|
62
64
|
});
|
|
65
|
+
dispatch(strapiAdmin.adminApi.util.invalidateTags([
|
|
66
|
+
'HomepageKeyStatistics'
|
|
67
|
+
]));
|
|
63
68
|
},
|
|
64
69
|
onError (error) {
|
|
65
70
|
toggleNotification({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBulkRemove.js","sources":["../../../admin/src/hooks/useBulkRemove.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { BulkDeleteFiles, File } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport type { BulkDeleteFolders, FolderDefinition } from '../../../shared/contracts/folders';\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ntype BulkRemovePayload = Partial<BulkDeleteFiles.Request['body']> &\n Partial<BulkDeleteFolders.Request['body']>;\n\nexport const useBulkRemove = () => {\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkRemoveQuery = (filesAndFolders: Array<FileWithType | FolderDefinition>) => {\n const payload = filesAndFolders.reduce<BulkRemovePayload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-delete', payload);\n };\n\n const mutation = useMutation<\n BulkDeleteFiles.Response | BulkDeleteFolders.Response,\n BulkDeleteFiles.Response['error'] | BulkDeleteFolders.Response['error'],\n Array<FileWithType | FolderDefinition>\n >(bulkRemoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n if (data?.folders?.length > 0) {\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n }\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.remove.success-label'),\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n },\n onError(error) {\n toggleNotification({ type: 'danger', message: error?.message });\n },\n });\n\n const remove = (...args: Parameters<typeof mutation.mutateAsync>) =>\n mutation.mutateAsync(...args);\n\n return { ...mutation, remove };\n};\n"],"names":["useBulkRemove","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","post","useFetchClient","bulkRemoveQuery","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","folders","message","getTrad","defaultMessage","onError","error","remove","args","mutateAsync"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBulkRemove.js","sources":["../../../admin/src/hooks/useBulkRemove.ts"],"sourcesContent":["import { useNotification, useFetchClient, adminApi } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\nimport { useDispatch } from 'react-redux';\n\nimport { BulkDeleteFiles, File } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport type { BulkDeleteFolders, FolderDefinition } from '../../../shared/contracts/folders';\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ntype BulkRemovePayload = Partial<BulkDeleteFiles.Request['body']> &\n Partial<BulkDeleteFolders.Request['body']>;\n\nexport const useBulkRemove = () => {\n const dispatch = useDispatch();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkRemoveQuery = (filesAndFolders: Array<FileWithType | FolderDefinition>) => {\n const payload = filesAndFolders.reduce<BulkRemovePayload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-delete', payload);\n };\n\n const mutation = useMutation<\n BulkDeleteFiles.Response | BulkDeleteFolders.Response,\n BulkDeleteFiles.Response['error'] | BulkDeleteFolders.Response['error'],\n Array<FileWithType | FolderDefinition>\n >(bulkRemoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n if (data?.folders?.length > 0) {\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n }\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.remove.success-label'),\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n\n dispatch(adminApi.util.invalidateTags(['HomepageKeyStatistics']));\n },\n onError(error) {\n toggleNotification({ type: 'danger', message: error?.message });\n },\n });\n\n const remove = (...args: Parameters<typeof mutation.mutateAsync>) =>\n mutation.mutateAsync(...args);\n\n return { ...mutation, remove };\n};\n"],"names":["useBulkRemove","dispatch","useDispatch","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","post","useFetchClient","bulkRemoveQuery","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","folders","message","getTrad","defaultMessage","adminApi","util","invalidateTags","onError","error","remove","args","mutateAsync"],"mappings":";;;;;;;;;;;;;;MAkBaA,aAAgB,GAAA,IAAA;AAC3B,IAAA,MAAMC,QAAWC,GAAAA,sBAAAA,EAAAA;IACjB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;IACpB,MAAM,EAAEC,IAAI,EAAE,GAAGC,0BAAAA,EAAAA;AAEjB,IAA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BAAA;iBAAU,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACnE;YAEA3B,kBAAmB,CAAA;gBACjBe,IAAM,EAAA,SAAA;AACNc,gBAAAA,OAAAA,EAAS3B,aAAc,CAAA;AACrBY,oBAAAA,EAAAA,EAAIgB,eAAQ,CAAA,4BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AAEAjC,YAAAA,QAAAA,CAASkC,oBAASC,CAAAA,IAAI,CAACC,cAAc,CAAC;AAAC,gBAAA;AAAwB,aAAA,CAAA,CAAA;AACjE,SAAA;AACAC,QAAAA,OAAAA,CAAAA,CAAQC,KAAK,EAAA;YACXpC,kBAAmB,CAAA;gBAAEe,IAAM,EAAA,QAAA;AAAUc,gBAAAA,OAAAA,EAASO,KAAOP,EAAAA;AAAQ,aAAA,CAAA;AAC/D;AACF,KAAA,CAAA;AAEA,IAAA,MAAMQ,SAAS,CAAC,GAAGC,IACjBpB,GAAAA,QAAAA,CAASqB,WAAW,CAAID,GAAAA,IAAAA,CAAAA;IAE1B,OAAO;AAAE,QAAA,GAAGpB,QAAQ;AAAEmB,QAAAA;AAAO,KAAA;AAC/B;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
|
|
1
|
+
import { useNotification, useFetchClient, adminApi } from '@strapi/admin/strapi-admin';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
3
|
import { useQueryClient, useMutation } from 'react-query';
|
|
4
|
+
import { useDispatch } from 'react-redux';
|
|
4
5
|
import { pluginId } from '../pluginId.mjs';
|
|
5
6
|
import 'byte-size';
|
|
6
7
|
import 'date-fns';
|
|
@@ -10,6 +11,7 @@ import '../constants.mjs';
|
|
|
10
11
|
import '../utils/urlYupSchema.mjs';
|
|
11
12
|
|
|
12
13
|
const useBulkRemove = ()=>{
|
|
14
|
+
const dispatch = useDispatch();
|
|
13
15
|
const { toggleNotification } = useNotification();
|
|
14
16
|
const { formatMessage } = useIntl();
|
|
15
17
|
const queryClient = useQueryClient();
|
|
@@ -58,6 +60,9 @@ const useBulkRemove = ()=>{
|
|
|
58
60
|
defaultMessage: 'Elements have been successfully deleted.'
|
|
59
61
|
})
|
|
60
62
|
});
|
|
63
|
+
dispatch(adminApi.util.invalidateTags([
|
|
64
|
+
'HomepageKeyStatistics'
|
|
65
|
+
]));
|
|
61
66
|
},
|
|
62
67
|
onError (error) {
|
|
63
68
|
toggleNotification({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBulkRemove.mjs","sources":["../../../admin/src/hooks/useBulkRemove.ts"],"sourcesContent":["import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { BulkDeleteFiles, File } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport type { BulkDeleteFolders, FolderDefinition } from '../../../shared/contracts/folders';\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ntype BulkRemovePayload = Partial<BulkDeleteFiles.Request['body']> &\n Partial<BulkDeleteFolders.Request['body']>;\n\nexport const useBulkRemove = () => {\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkRemoveQuery = (filesAndFolders: Array<FileWithType | FolderDefinition>) => {\n const payload = filesAndFolders.reduce<BulkRemovePayload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-delete', payload);\n };\n\n const mutation = useMutation<\n BulkDeleteFiles.Response | BulkDeleteFolders.Response,\n BulkDeleteFiles.Response['error'] | BulkDeleteFolders.Response['error'],\n Array<FileWithType | FolderDefinition>\n >(bulkRemoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n if (data?.folders?.length > 0) {\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n }\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.remove.success-label'),\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n },\n onError(error) {\n toggleNotification({ type: 'danger', message: error?.message });\n },\n });\n\n const remove = (...args: Parameters<typeof mutation.mutateAsync>) =>\n mutation.mutateAsync(...args);\n\n return { ...mutation, remove };\n};\n"],"names":["useBulkRemove","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","post","useFetchClient","bulkRemoveQuery","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","folders","message","getTrad","defaultMessage","onError","error","remove","args","mutateAsync"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useBulkRemove.mjs","sources":["../../../admin/src/hooks/useBulkRemove.ts"],"sourcesContent":["import { useNotification, useFetchClient, adminApi } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient } from 'react-query';\nimport { useDispatch } from 'react-redux';\n\nimport { BulkDeleteFiles, File } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\nimport { getTrad } from '../utils';\n\nimport type { BulkDeleteFolders, FolderDefinition } from '../../../shared/contracts/folders';\n\nexport interface FileWithType extends File {\n type: string;\n}\n\ntype BulkRemovePayload = Partial<BulkDeleteFiles.Request['body']> &\n Partial<BulkDeleteFolders.Request['body']>;\n\nexport const useBulkRemove = () => {\n const dispatch = useDispatch();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { post } = useFetchClient();\n\n const bulkRemoveQuery = (filesAndFolders: Array<FileWithType | FolderDefinition>) => {\n const payload = filesAndFolders.reduce<BulkRemovePayload>((acc, selected) => {\n const { id, type } = selected;\n const key = type === 'asset' ? 'fileIds' : 'folderIds';\n\n if (!acc[key]) {\n acc[key] = [];\n }\n\n acc[key]!.push(id);\n\n return acc;\n }, {});\n\n return post('/upload/actions/bulk-delete', payload);\n };\n\n const mutation = useMutation<\n BulkDeleteFiles.Response | BulkDeleteFolders.Response,\n BulkDeleteFiles.Response['error'] | BulkDeleteFolders.Response['error'],\n Array<FileWithType | FolderDefinition>\n >(bulkRemoveQuery, {\n onSuccess(res) {\n const {\n data: { data },\n } = res;\n\n if (data?.files?.length > 0) {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n }\n\n if (data?.folders?.length > 0) {\n queryClient.refetchQueries([pluginId, 'folders'], { active: true });\n }\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: getTrad('modal.remove.success-label'),\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n\n dispatch(adminApi.util.invalidateTags(['HomepageKeyStatistics']));\n },\n onError(error) {\n toggleNotification({ type: 'danger', message: error?.message });\n },\n });\n\n const remove = (...args: Parameters<typeof mutation.mutateAsync>) =>\n mutation.mutateAsync(...args);\n\n return { ...mutation, remove };\n};\n"],"names":["useBulkRemove","dispatch","useDispatch","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","post","useFetchClient","bulkRemoveQuery","filesAndFolders","payload","reduce","acc","selected","id","type","key","push","mutation","useMutation","onSuccess","res","data","files","length","refetchQueries","pluginId","active","folders","message","getTrad","defaultMessage","adminApi","util","invalidateTags","onError","error","remove","args","mutateAsync"],"mappings":";;;;;;;;;;;;MAkBaA,aAAgB,GAAA,IAAA;AAC3B,IAAA,MAAMC,QAAWC,GAAAA,WAAAA,EAAAA;IACjB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,aA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EA,IAAIL,IAAAA,EAAMM,OAASJ,EAAAA,MAAAA,GAAS,CAAG,EAAA;AAC7BpB,gBAAAA,WAAAA,CAAYqB,cAAc,CAAC;AAACC,oBAAAA,QAAAA;AAAU,oBAAA;iBAAU,EAAE;oBAAEC,MAAQ,EAAA;AAAK,iBAAA,CAAA;AACnE;YAEA3B,kBAAmB,CAAA;gBACjBe,IAAM,EAAA,SAAA;AACNc,gBAAAA,OAAAA,EAAS3B,aAAc,CAAA;AACrBY,oBAAAA,EAAAA,EAAIgB,OAAQ,CAAA,4BAAA,CAAA;oBACZC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AAEAjC,YAAAA,QAAAA,CAASkC,QAASC,CAAAA,IAAI,CAACC,cAAc,CAAC;AAAC,gBAAA;AAAwB,aAAA,CAAA,CAAA;AACjE,SAAA;AACAC,QAAAA,OAAAA,CAAAA,CAAQC,KAAK,EAAA;YACXpC,kBAAmB,CAAA;gBAAEe,IAAM,EAAA,QAAA;AAAUc,gBAAAA,OAAAA,EAASO,KAAOP,EAAAA;AAAQ,aAAA,CAAA;AAC/D;AACF,KAAA,CAAA;AAEA,IAAA,MAAMQ,SAAS,CAAC,GAAGC,IACjBpB,GAAAA,QAAAA,CAASqB,WAAW,CAAID,GAAAA,IAAAA,CAAAA;IAE1B,OAAO;AAAE,QAAA,GAAGpB,QAAQ;AAAEmB,QAAAA;AAAO,KAAA;AAC/B;;;;"}
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
var strapiAdmin = require('@strapi/admin/strapi-admin');
|
|
4
4
|
var reactIntl = require('react-intl');
|
|
5
5
|
var reactQuery = require('react-query');
|
|
6
|
+
var reactRedux = require('react-redux');
|
|
6
7
|
var pluginId = require('../pluginId.js');
|
|
7
8
|
|
|
8
9
|
const useRemoveAsset = (onSuccess)=>{
|
|
10
|
+
const dispatch = reactRedux.useDispatch();
|
|
9
11
|
const { toggleNotification } = strapiAdmin.useNotification();
|
|
10
12
|
const { formatMessage } = reactIntl.useIntl();
|
|
11
13
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -31,6 +33,9 @@ const useRemoveAsset = (onSuccess)=>{
|
|
|
31
33
|
defaultMessage: 'Elements have been successfully deleted.'
|
|
32
34
|
})
|
|
33
35
|
});
|
|
36
|
+
dispatch(strapiAdmin.adminApi.util.invalidateTags([
|
|
37
|
+
'HomepageKeyStatistics'
|
|
38
|
+
]));
|
|
34
39
|
onSuccess();
|
|
35
40
|
},
|
|
36
41
|
onError (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoveAsset.js","sources":["../../../admin/src/hooks/useRemoveAsset.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useRemoveAsset.js","sources":["../../../admin/src/hooks/useRemoveAsset.ts"],"sourcesContent":["import {\n useNotification,\n useFetchClient,\n FetchResponse,\n adminApi,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient, UseMutationResult } from 'react-query';\nimport { useDispatch } from 'react-redux';\n\nimport { pluginId } from '../pluginId';\n\nimport type { DeleteFile } from '../../../shared/contracts/files';\n\ntype UseRemoveAsset = {\n removeAsset: (assetId: number) => Promise<void>;\n} & UseMutationResult<FetchResponse<DeleteFile.Response>, Error, number>;\n\nexport const useRemoveAsset = (onSuccess: () => void): UseRemoveAsset => {\n const dispatch = useDispatch();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { del } = useFetchClient();\n\n const mutation = useMutation(\n (assetId: number) => del<DeleteFile.Response>(`/upload/files/${assetId}`),\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: 'modal.remove.success-label',\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n dispatch(adminApi.util.invalidateTags(['HomepageKeyStatistics']));\n\n onSuccess();\n },\n onError(error: Error) {\n toggleNotification({ type: 'danger', message: error.message });\n },\n }\n );\n\n const removeAsset = async (assetId: number) => {\n await mutation.mutateAsync(assetId);\n };\n\n return { ...mutation, removeAsset };\n};\n"],"names":["useRemoveAsset","onSuccess","dispatch","useDispatch","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","del","useFetchClient","mutation","useMutation","assetId","refetchQueries","pluginId","active","type","message","id","defaultMessage","adminApi","util","invalidateTags","onError","error","removeAsset","mutateAsync"],"mappings":";;;;;;;;AAkBO,MAAMA,iBAAiB,CAACC,SAAAA,GAAAA;AAC7B,IAAA,MAAMC,QAAWC,GAAAA,sBAAAA,EAAAA;IACjB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;IACpB,MAAM,EAAEC,GAAG,EAAE,GAAGC,0BAAAA,EAAAA;IAEhB,MAAMC,QAAAA,GAAWC,sBACf,CAAA,CAACC,OAAoBJ,GAAAA,GAAAA,CAAyB,CAAC,cAAc,EAAEI,OAAQ,CAAA,CAAC,CACxE,EAAA;AACEb,QAAAA,SAAAA,CAAAA,GAAAA;AACEO,YAAAA,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAS,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;AAChET,YAAAA,WAAAA,CAAYO,cAAc,CAAC;AAACC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAc,EAAE;gBAAEC,MAAQ,EAAA;AAAK,aAAA,CAAA;YAErEb,kBAAmB,CAAA;gBACjBc,IAAM,EAAA,SAAA;AACNC,gBAAAA,OAAAA,EAASb,aAAc,CAAA;oBACrBc,EAAI,EAAA,4BAAA;oBACJC,cAAgB,EAAA;AAClB,iBAAA;AACF,aAAA,CAAA;AACAnB,YAAAA,QAAAA,CAASoB,oBAASC,CAAAA,IAAI,CAACC,cAAc,CAAC;AAAC,gBAAA;AAAwB,aAAA,CAAA,CAAA;AAE/DvB,YAAAA,SAAAA,EAAAA;AACF,SAAA;AACAwB,QAAAA,OAAAA,CAAAA,CAAQC,KAAY,EAAA;YAClBtB,kBAAmB,CAAA;gBAAEc,IAAM,EAAA,QAAA;AAAUC,gBAAAA,OAAAA,EAASO,MAAMP;AAAQ,aAAA,CAAA;AAC9D;AACF,KAAA,CAAA;AAGF,IAAA,MAAMQ,cAAc,OAAOb,OAAAA,GAAAA;QACzB,MAAMF,QAAAA,CAASgB,WAAW,CAACd,OAAAA,CAAAA;AAC7B,KAAA;IAEA,OAAO;AAAE,QAAA,GAAGF,QAAQ;AAAEe,QAAAA;AAAY,KAAA;AACpC;;;;"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { useNotification, useFetchClient } from '@strapi/admin/strapi-admin';
|
|
1
|
+
import { useNotification, useFetchClient, adminApi } from '@strapi/admin/strapi-admin';
|
|
2
2
|
import { useIntl } from 'react-intl';
|
|
3
3
|
import { useQueryClient, useMutation } from 'react-query';
|
|
4
|
+
import { useDispatch } from 'react-redux';
|
|
4
5
|
import { pluginId } from '../pluginId.mjs';
|
|
5
6
|
|
|
6
7
|
const useRemoveAsset = (onSuccess)=>{
|
|
8
|
+
const dispatch = useDispatch();
|
|
7
9
|
const { toggleNotification } = useNotification();
|
|
8
10
|
const { formatMessage } = useIntl();
|
|
9
11
|
const queryClient = useQueryClient();
|
|
@@ -29,6 +31,9 @@ const useRemoveAsset = (onSuccess)=>{
|
|
|
29
31
|
defaultMessage: 'Elements have been successfully deleted.'
|
|
30
32
|
})
|
|
31
33
|
});
|
|
34
|
+
dispatch(adminApi.util.invalidateTags([
|
|
35
|
+
'HomepageKeyStatistics'
|
|
36
|
+
]));
|
|
32
37
|
onSuccess();
|
|
33
38
|
},
|
|
34
39
|
onError (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoveAsset.mjs","sources":["../../../admin/src/hooks/useRemoveAsset.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useRemoveAsset.mjs","sources":["../../../admin/src/hooks/useRemoveAsset.ts"],"sourcesContent":["import {\n useNotification,\n useFetchClient,\n FetchResponse,\n adminApi,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useMutation, useQueryClient, UseMutationResult } from 'react-query';\nimport { useDispatch } from 'react-redux';\n\nimport { pluginId } from '../pluginId';\n\nimport type { DeleteFile } from '../../../shared/contracts/files';\n\ntype UseRemoveAsset = {\n removeAsset: (assetId: number) => Promise<void>;\n} & UseMutationResult<FetchResponse<DeleteFile.Response>, Error, number>;\n\nexport const useRemoveAsset = (onSuccess: () => void): UseRemoveAsset => {\n const dispatch = useDispatch();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const queryClient = useQueryClient();\n const { del } = useFetchClient();\n\n const mutation = useMutation(\n (assetId: number) => del<DeleteFile.Response>(`/upload/files/${assetId}`),\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n\n toggleNotification({\n type: 'success',\n message: formatMessage({\n id: 'modal.remove.success-label',\n defaultMessage: 'Elements have been successfully deleted.',\n }),\n });\n dispatch(adminApi.util.invalidateTags(['HomepageKeyStatistics']));\n\n onSuccess();\n },\n onError(error: Error) {\n toggleNotification({ type: 'danger', message: error.message });\n },\n }\n );\n\n const removeAsset = async (assetId: number) => {\n await mutation.mutateAsync(assetId);\n };\n\n return { ...mutation, removeAsset };\n};\n"],"names":["useRemoveAsset","onSuccess","dispatch","useDispatch","toggleNotification","useNotification","formatMessage","useIntl","queryClient","useQueryClient","del","useFetchClient","mutation","useMutation","assetId","refetchQueries","pluginId","active","type","message","id","defaultMessage","adminApi","util","invalidateTags","onError","error","removeAsset","mutateAsync"],"mappings":";;;;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cAAc,OAAOb,OAAAA,GAAAA;QACzB,MAAMF,QAAAA,CAASgB,WAAW,CAACd,OAAAA,CAAAA;AAC7B,KAAA;IAEA,OAAO;AAAE,QAAA,GAAGF,QAAQ;AAAEe,QAAAA;AAAY,KAAA;AACpC;;;;"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var strapiAdmin = require('@strapi/admin/strapi-admin');
|
|
5
5
|
var reactQuery = require('react-query');
|
|
6
|
+
var reactRedux = require('react-redux');
|
|
6
7
|
var pluginId = require('../pluginId.js');
|
|
7
8
|
|
|
8
9
|
function _interopNamespaceDefault(e) {
|
|
@@ -44,6 +45,7 @@ const uploadAsset = (asset, folderId, signal, onProgress, post)=>{
|
|
|
44
45
|
}).then((res)=>res.data);
|
|
45
46
|
};
|
|
46
47
|
const useUpload = ()=>{
|
|
48
|
+
const dispatch = reactRedux.useDispatch();
|
|
47
49
|
const [progress, setProgress] = React__namespace.useState(0);
|
|
48
50
|
const queryClient = reactQuery.useQueryClient();
|
|
49
51
|
const abortController = new AbortController();
|
|
@@ -65,6 +67,9 @@ const useUpload = ()=>{
|
|
|
65
67
|
], {
|
|
66
68
|
active: true
|
|
67
69
|
});
|
|
70
|
+
dispatch(strapiAdmin.adminApi.util.invalidateTags([
|
|
71
|
+
'HomepageKeyStatistics'
|
|
72
|
+
]));
|
|
68
73
|
}
|
|
69
74
|
});
|
|
70
75
|
const upload = (asset, folderId)=>mutation.mutateAsync({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpload.js","sources":["../../../admin/src/hooks/useUpload.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useFetchClient, FetchClient } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { File, RawFile, CreateFile } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}`;\n\ninterface Asset extends Omit<File, 'id' | 'hash'> {\n rawFile?: RawFile;\n id?: File['id'];\n hash?: File['hash'];\n}\n\nconst uploadAsset = (\n asset: Asset,\n folderId: number | null,\n signal: AbortSignal,\n onProgress: (progress: number) => void,\n post: FetchClient['post']\n) => {\n const { rawFile, caption, name, alternativeText } = asset;\n const formData = new FormData();\n\n formData.append('files', rawFile!);\n\n formData.append(\n 'fileInfo',\n JSON.stringify({\n name,\n caption,\n alternativeText,\n folder: folderId,\n })\n );\n\n /**\n * onProgress is not possible using native fetch\n * need to look into an alternative to make it work\n * perhaps using xhr like Axios does\n */\n return post(endpoint, formData, {\n signal,\n }).then((res) => res.data);\n};\n\nexport const useUpload = () => {\n const [progress, setProgress] = React.useState(0);\n const queryClient = useQueryClient();\n const abortController = new AbortController();\n const signal = abortController.signal;\n const { post } = useFetchClient();\n\n const mutation = useMutation<\n CreateFile.Response['data'],\n CreateFile.Response['error'],\n { asset: Asset; folderId: number | null }\n >(\n ({ asset, folderId }) => {\n return uploadAsset(asset, folderId, signal, setProgress, post);\n },\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n },\n }\n );\n\n const upload = (asset: Asset, folderId: number | null) =>\n mutation.mutateAsync({ asset, folderId });\n\n const cancel = () => abortController.abort();\n\n return {\n upload,\n isLoading: mutation.isLoading,\n cancel,\n error: mutation.error,\n progress,\n status: mutation.status,\n };\n};\n"],"names":["endpoint","pluginId","uploadAsset","asset","folderId","signal","onProgress","post","rawFile","caption","name","alternativeText","formData","FormData","append","JSON","stringify","folder","then","res","data","useUpload","progress","setProgress","React","useState","queryClient","useQueryClient","abortController","AbortController","useFetchClient","mutation","useMutation","onSuccess","refetchQueries","active","upload","mutateAsync","cancel","abort","isLoading","error","status"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUpload.js","sources":["../../../admin/src/hooks/useUpload.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useFetchClient, FetchClient, adminApi } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\nimport { useDispatch } from 'react-redux';\n\nimport { File, RawFile, CreateFile } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}`;\n\ninterface Asset extends Omit<File, 'id' | 'hash'> {\n rawFile?: RawFile;\n id?: File['id'];\n hash?: File['hash'];\n}\n\nconst uploadAsset = (\n asset: Asset,\n folderId: number | null,\n signal: AbortSignal,\n onProgress: (progress: number) => void,\n post: FetchClient['post']\n) => {\n const { rawFile, caption, name, alternativeText } = asset;\n const formData = new FormData();\n\n formData.append('files', rawFile!);\n\n formData.append(\n 'fileInfo',\n JSON.stringify({\n name,\n caption,\n alternativeText,\n folder: folderId,\n })\n );\n\n /**\n * onProgress is not possible using native fetch\n * need to look into an alternative to make it work\n * perhaps using xhr like Axios does\n */\n return post(endpoint, formData, {\n signal,\n }).then((res) => res.data);\n};\n\nexport const useUpload = () => {\n const dispatch = useDispatch();\n const [progress, setProgress] = React.useState(0);\n const queryClient = useQueryClient();\n const abortController = new AbortController();\n const signal = abortController.signal;\n const { post } = useFetchClient();\n\n const mutation = useMutation<\n CreateFile.Response['data'],\n CreateFile.Response['error'],\n { asset: Asset; folderId: number | null }\n >(\n ({ asset, folderId }) => {\n return uploadAsset(asset, folderId, signal, setProgress, post);\n },\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n dispatch(adminApi.util.invalidateTags(['HomepageKeyStatistics']));\n },\n }\n );\n\n const upload = (asset: Asset, folderId: number | null) =>\n mutation.mutateAsync({ asset, folderId });\n\n const cancel = () => abortController.abort();\n\n return {\n upload,\n isLoading: mutation.isLoading,\n cancel,\n error: mutation.error,\n progress,\n status: mutation.status,\n };\n};\n"],"names":["endpoint","pluginId","uploadAsset","asset","folderId","signal","onProgress","post","rawFile","caption","name","alternativeText","formData","FormData","append","JSON","stringify","folder","then","res","data","useUpload","dispatch","useDispatch","progress","setProgress","React","useState","queryClient","useQueryClient","abortController","AbortController","useFetchClient","mutation","useMutation","onSuccess","refetchQueries","active","adminApi","util","invalidateTags","upload","mutateAsync","cancel","abort","isLoading","error","status"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAMA,QAAW,GAAA,CAAC,CAAC,EAAEC,kBAAS,CAAC;AAQ/B,MAAMC,WAAc,GAAA,CAClBC,KACAC,EAAAA,QAAAA,EACAC,QACAC,UACAC,EAAAA,IAAAA,GAAAA;IAEA,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAEC,IAAI,EAAEC,eAAe,EAAE,GAAGR,KAAAA;AACpD,IAAA,MAAMS,WAAW,IAAIC,QAAAA,EAAAA;IAErBD,QAASE,CAAAA,MAAM,CAAC,OAASN,EAAAA,OAAAA,CAAAA;AAEzBI,IAAAA,QAAAA,CAASE,MAAM,CACb,UACAC,EAAAA,IAAAA,CAAKC,SAAS,CAAC;AACbN,QAAAA,IAAAA;AACAD,QAAAA,OAAAA;AACAE,QAAAA,eAAAA;QACAM,MAAQb,EAAAA;AACV,KAAA,CAAA,CAAA;AAGF;;;;MAKA,OAAOG,IAAKP,CAAAA,QAAAA,EAAUY,QAAU,EAAA;AAC9BP,QAAAA;AACF,KAAA,CAAA,CAAGa,IAAI,CAAC,CAACC,GAAAA,GAAQA,IAAIC,IAAI,CAAA;AAC3B,CAAA;MAEaC,SAAY,GAAA,IAAA;AACvB,IAAA,MAAMC,QAAWC,GAAAA,sBAAAA,EAAAA;AACjB,IAAA,MAAM,CAACC,QAAUC,EAAAA,WAAAA,CAAY,GAAGC,gBAAAA,CAAMC,QAAQ,CAAC,CAAA,CAAA;AAC/C,IAAA,MAAMC,WAAcC,GAAAA,yBAAAA,EAAAA;AACpB,IAAA,MAAMC,kBAAkB,IAAIC,eAAAA,EAAAA;IAC5B,MAAM1B,MAAAA,GAASyB,gBAAgBzB,MAAM;IACrC,MAAM,EAAEE,IAAI,EAAE,GAAGyB,0BAAAA,EAAAA;AAEjB,IAAA,MAAMC,WAAWC,sBAKf,CAAA,CAAC,EAAE/B,KAAK,EAAEC,QAAQ,EAAE,GAAA;AAClB,QAAA,OAAOF,WAAYC,CAAAA,KAAAA,EAAOC,QAAUC,EAAAA,MAAAA,EAAQoB,WAAalB,EAAAA,IAAAA,CAAAA;KAE3D,EAAA;AACE4B,QAAAA,SAAAA,CAAAA,GAAAA;AACEP,YAAAA,WAAAA,CAAYQ,cAAc,CAAC;AAACnC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAS,EAAE;gBAAEoC,MAAQ,EAAA;AAAK,aAAA,CAAA;AAChET,YAAAA,WAAAA,CAAYQ,cAAc,CAAC;AAACnC,gBAAAA,iBAAAA;AAAU,gBAAA;aAAc,EAAE;gBAAEoC,MAAQ,EAAA;AAAK,aAAA,CAAA;AACrEf,YAAAA,QAAAA,CAASgB,oBAASC,CAAAA,IAAI,CAACC,cAAc,CAAC;AAAC,gBAAA;AAAwB,aAAA,CAAA,CAAA;AACjE;AACF,KAAA,CAAA;AAGF,IAAA,MAAMC,SAAS,CAACtC,KAAAA,EAAcC,QAC5B6B,GAAAA,QAAAA,CAASS,WAAW,CAAC;AAAEvC,YAAAA,KAAAA;AAAOC,YAAAA;AAAS,SAAA,CAAA;IAEzC,MAAMuC,MAAAA,GAAS,IAAMb,eAAAA,CAAgBc,KAAK,EAAA;IAE1C,OAAO;AACLH,QAAAA,MAAAA;AACAI,QAAAA,SAAAA,EAAWZ,SAASY,SAAS;AAC7BF,QAAAA,MAAAA;AACAG,QAAAA,KAAAA,EAAOb,SAASa,KAAK;AACrBtB,QAAAA,QAAAA;AACAuB,QAAAA,MAAAA,EAAQd,SAASc;AACnB,KAAA;AACF;;;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useFetchClient } from '@strapi/admin/strapi-admin';
|
|
2
|
+
import { useFetchClient, adminApi } from '@strapi/admin/strapi-admin';
|
|
3
3
|
import { useQueryClient, useMutation } from 'react-query';
|
|
4
|
+
import { useDispatch } from 'react-redux';
|
|
4
5
|
import { pluginId } from '../pluginId.mjs';
|
|
5
6
|
|
|
6
7
|
const endpoint = `/${pluginId}`;
|
|
@@ -23,6 +24,7 @@ const uploadAsset = (asset, folderId, signal, onProgress, post)=>{
|
|
|
23
24
|
}).then((res)=>res.data);
|
|
24
25
|
};
|
|
25
26
|
const useUpload = ()=>{
|
|
27
|
+
const dispatch = useDispatch();
|
|
26
28
|
const [progress, setProgress] = React.useState(0);
|
|
27
29
|
const queryClient = useQueryClient();
|
|
28
30
|
const abortController = new AbortController();
|
|
@@ -44,6 +46,9 @@ const useUpload = ()=>{
|
|
|
44
46
|
], {
|
|
45
47
|
active: true
|
|
46
48
|
});
|
|
49
|
+
dispatch(adminApi.util.invalidateTags([
|
|
50
|
+
'HomepageKeyStatistics'
|
|
51
|
+
]));
|
|
47
52
|
}
|
|
48
53
|
});
|
|
49
54
|
const upload = (asset, folderId)=>mutation.mutateAsync({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUpload.mjs","sources":["../../../admin/src/hooks/useUpload.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useFetchClient, FetchClient } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\n\nimport { File, RawFile, CreateFile } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}`;\n\ninterface Asset extends Omit<File, 'id' | 'hash'> {\n rawFile?: RawFile;\n id?: File['id'];\n hash?: File['hash'];\n}\n\nconst uploadAsset = (\n asset: Asset,\n folderId: number | null,\n signal: AbortSignal,\n onProgress: (progress: number) => void,\n post: FetchClient['post']\n) => {\n const { rawFile, caption, name, alternativeText } = asset;\n const formData = new FormData();\n\n formData.append('files', rawFile!);\n\n formData.append(\n 'fileInfo',\n JSON.stringify({\n name,\n caption,\n alternativeText,\n folder: folderId,\n })\n );\n\n /**\n * onProgress is not possible using native fetch\n * need to look into an alternative to make it work\n * perhaps using xhr like Axios does\n */\n return post(endpoint, formData, {\n signal,\n }).then((res) => res.data);\n};\n\nexport const useUpload = () => {\n const [progress, setProgress] = React.useState(0);\n const queryClient = useQueryClient();\n const abortController = new AbortController();\n const signal = abortController.signal;\n const { post } = useFetchClient();\n\n const mutation = useMutation<\n CreateFile.Response['data'],\n CreateFile.Response['error'],\n { asset: Asset; folderId: number | null }\n >(\n ({ asset, folderId }) => {\n return uploadAsset(asset, folderId, signal, setProgress, post);\n },\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n },\n }\n );\n\n const upload = (asset: Asset, folderId: number | null) =>\n mutation.mutateAsync({ asset, folderId });\n\n const cancel = () => abortController.abort();\n\n return {\n upload,\n isLoading: mutation.isLoading,\n cancel,\n error: mutation.error,\n progress,\n status: mutation.status,\n };\n};\n"],"names":["endpoint","pluginId","uploadAsset","asset","folderId","signal","onProgress","post","rawFile","caption","name","alternativeText","formData","FormData","append","JSON","stringify","folder","then","res","data","useUpload","progress","setProgress","React","useState","queryClient","useQueryClient","abortController","AbortController","useFetchClient","mutation","useMutation","onSuccess","refetchQueries","active","upload","mutateAsync","cancel","abort","isLoading","error","status"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUpload.mjs","sources":["../../../admin/src/hooks/useUpload.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useFetchClient, FetchClient, adminApi } from '@strapi/admin/strapi-admin';\nimport { useMutation, useQueryClient } from 'react-query';\nimport { useDispatch } from 'react-redux';\n\nimport { File, RawFile, CreateFile } from '../../../shared/contracts/files';\nimport { pluginId } from '../pluginId';\n\nconst endpoint = `/${pluginId}`;\n\ninterface Asset extends Omit<File, 'id' | 'hash'> {\n rawFile?: RawFile;\n id?: File['id'];\n hash?: File['hash'];\n}\n\nconst uploadAsset = (\n asset: Asset,\n folderId: number | null,\n signal: AbortSignal,\n onProgress: (progress: number) => void,\n post: FetchClient['post']\n) => {\n const { rawFile, caption, name, alternativeText } = asset;\n const formData = new FormData();\n\n formData.append('files', rawFile!);\n\n formData.append(\n 'fileInfo',\n JSON.stringify({\n name,\n caption,\n alternativeText,\n folder: folderId,\n })\n );\n\n /**\n * onProgress is not possible using native fetch\n * need to look into an alternative to make it work\n * perhaps using xhr like Axios does\n */\n return post(endpoint, formData, {\n signal,\n }).then((res) => res.data);\n};\n\nexport const useUpload = () => {\n const dispatch = useDispatch();\n const [progress, setProgress] = React.useState(0);\n const queryClient = useQueryClient();\n const abortController = new AbortController();\n const signal = abortController.signal;\n const { post } = useFetchClient();\n\n const mutation = useMutation<\n CreateFile.Response['data'],\n CreateFile.Response['error'],\n { asset: Asset; folderId: number | null }\n >(\n ({ asset, folderId }) => {\n return uploadAsset(asset, folderId, signal, setProgress, post);\n },\n {\n onSuccess() {\n queryClient.refetchQueries([pluginId, 'assets'], { active: true });\n queryClient.refetchQueries([pluginId, 'asset-count'], { active: true });\n dispatch(adminApi.util.invalidateTags(['HomepageKeyStatistics']));\n },\n }\n );\n\n const upload = (asset: Asset, folderId: number | null) =>\n mutation.mutateAsync({ asset, folderId });\n\n const cancel = () => abortController.abort();\n\n return {\n upload,\n isLoading: mutation.isLoading,\n cancel,\n error: mutation.error,\n progress,\n status: mutation.status,\n };\n};\n"],"names":["endpoint","pluginId","uploadAsset","asset","folderId","signal","onProgress","post","rawFile","caption","name","alternativeText","formData","FormData","append","JSON","stringify","folder","then","res","data","useUpload","dispatch","useDispatch","progress","setProgress","React","useState","queryClient","useQueryClient","abortController","AbortController","useFetchClient","mutation","useMutation","onSuccess","refetchQueries","active","adminApi","util","invalidateTags","upload","mutateAsync","cancel","abort","isLoading","error","status"],"mappings":";;;;;;AASA,MAAMA,QAAW,GAAA,CAAC,CAAC,EAAEC,SAAS,CAAC;AAQ/B,MAAMC,WAAc,GAAA,CAClBC,KACAC,EAAAA,QAAAA,EACAC,QACAC,UACAC,EAAAA,IAAAA,GA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U,gBAAA;aAAS,EAAE;gBAAEoC,MAAQ,EAAA;AAAK,aAAA,CAAA;AAChET,YAAAA,WAAAA,CAAYQ,cAAc,CAAC;AAACnC,gBAAAA,QAAAA;AAAU,gBAAA;aAAc,EAAE;gBAAEoC,MAAQ,EAAA;AAAK,aAAA,CAAA;AACrEf,YAAAA,QAAAA,CAASgB,QAASC,CAAAA,IAAI,CAACC,cAAc,CAAC;AAAC,gBAAA;AAAwB,aAAA,CAAA,CAAA;AACjE;AACF,KAAA,CAAA;AAGF,IAAA,MAAMC,SAAS,CAACtC,KAAAA,EAAcC,QAC5B6B,GAAAA,QAAAA,CAASS,WAAW,CAAC;AAAEvC,YAAAA,KAAAA;AAAOC,YAAAA;AAAS,SAAA,CAAA;IAEzC,MAAMuC,MAAAA,GAAS,IAAMb,eAAAA,CAAgBc,KAAK,EAAA;IAE1C,OAAO;AACLH,QAAAA,MAAAA;AACAI,QAAAA,SAAAA,EAAWZ,SAASY,SAAS;AAC7BF,QAAAA,MAAAA;AACAG,QAAAA,KAAAA,EAAOb,SAASa,KAAK;AACrBtB,QAAAA,QAAAA;AACAuB,QAAAA,MAAAA,EAAQd,SAASc;AACnB,KAAA;AACF;;;;"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var name = "@strapi/upload";
|
|
6
|
-
var version = "5.
|
|
6
|
+
var version = "5.21.0";
|
|
7
7
|
var description = "Makes it easy to upload images and files to your Strapi Application.";
|
|
8
8
|
var license = "SEE LICENSE IN LICENSE";
|
|
9
9
|
var author = {
|
|
@@ -64,10 +64,11 @@ var scripts = {
|
|
|
64
64
|
};
|
|
65
65
|
var dependencies = {
|
|
66
66
|
"@mux/mux-player-react": "3.1.0",
|
|
67
|
+
"@reduxjs/toolkit": "1.9.7",
|
|
67
68
|
"@strapi/design-system": "2.0.0-rc.29",
|
|
68
69
|
"@strapi/icons": "2.0.0-rc.29",
|
|
69
|
-
"@strapi/provider-upload-local": "5.
|
|
70
|
-
"@strapi/utils": "5.
|
|
70
|
+
"@strapi/provider-upload-local": "5.21.0",
|
|
71
|
+
"@strapi/utils": "5.21.0",
|
|
71
72
|
"byte-size": "8.1.1",
|
|
72
73
|
cropperjs: "1.6.1",
|
|
73
74
|
"date-fns": "2.30.0",
|
|
@@ -90,8 +91,8 @@ var dependencies = {
|
|
|
90
91
|
zod: "3.25.67"
|
|
91
92
|
};
|
|
92
93
|
var devDependencies = {
|
|
93
|
-
"@strapi/admin": "5.
|
|
94
|
-
"@strapi/types": "5.
|
|
94
|
+
"@strapi/admin": "5.21.0",
|
|
95
|
+
"@strapi/types": "5.21.0",
|
|
95
96
|
"@testing-library/dom": "10.1.0",
|
|
96
97
|
"@testing-library/react": "15.0.7",
|
|
97
98
|
"@testing-library/user-event": "14.5.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"package.json.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var name = "@strapi/upload";
|
|
2
|
-
var version = "5.
|
|
2
|
+
var version = "5.21.0";
|
|
3
3
|
var description = "Makes it easy to upload images and files to your Strapi Application.";
|
|
4
4
|
var license = "SEE LICENSE IN LICENSE";
|
|
5
5
|
var author = {
|
|
@@ -60,10 +60,11 @@ var scripts = {
|
|
|
60
60
|
};
|
|
61
61
|
var dependencies = {
|
|
62
62
|
"@mux/mux-player-react": "3.1.0",
|
|
63
|
+
"@reduxjs/toolkit": "1.9.7",
|
|
63
64
|
"@strapi/design-system": "2.0.0-rc.29",
|
|
64
65
|
"@strapi/icons": "2.0.0-rc.29",
|
|
65
|
-
"@strapi/provider-upload-local": "5.
|
|
66
|
-
"@strapi/utils": "5.
|
|
66
|
+
"@strapi/provider-upload-local": "5.21.0",
|
|
67
|
+
"@strapi/utils": "5.21.0",
|
|
67
68
|
"byte-size": "8.1.1",
|
|
68
69
|
cropperjs: "1.6.1",
|
|
69
70
|
"date-fns": "2.30.0",
|
|
@@ -86,8 +87,8 @@ var dependencies = {
|
|
|
86
87
|
zod: "3.25.67"
|
|
87
88
|
};
|
|
88
89
|
var devDependencies = {
|
|
89
|
-
"@strapi/admin": "5.
|
|
90
|
-
"@strapi/types": "5.
|
|
90
|
+
"@strapi/admin": "5.21.0",
|
|
91
|
+
"@strapi/types": "5.21.0",
|
|
91
92
|
"@testing-library/dom": "10.1.0",
|
|
92
93
|
"@testing-library/react": "15.0.7",
|
|
93
94
|
"@testing-library/user-event": "14.5.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"package.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/upload",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.21.0",
|
|
4
4
|
"description": "Makes it easy to upload images and files to your Strapi Application.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": {
|
|
@@ -61,10 +61,11 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@mux/mux-player-react": "3.1.0",
|
|
64
|
+
"@reduxjs/toolkit": "1.9.7",
|
|
64
65
|
"@strapi/design-system": "2.0.0-rc.29",
|
|
65
66
|
"@strapi/icons": "2.0.0-rc.29",
|
|
66
|
-
"@strapi/provider-upload-local": "5.
|
|
67
|
-
"@strapi/utils": "5.
|
|
67
|
+
"@strapi/provider-upload-local": "5.21.0",
|
|
68
|
+
"@strapi/utils": "5.21.0",
|
|
68
69
|
"byte-size": "8.1.1",
|
|
69
70
|
"cropperjs": "1.6.1",
|
|
70
71
|
"date-fns": "2.30.0",
|
|
@@ -87,8 +88,8 @@
|
|
|
87
88
|
"zod": "3.25.67"
|
|
88
89
|
},
|
|
89
90
|
"devDependencies": {
|
|
90
|
-
"@strapi/admin": "5.
|
|
91
|
-
"@strapi/types": "5.
|
|
91
|
+
"@strapi/admin": "5.21.0",
|
|
92
|
+
"@strapi/types": "5.21.0",
|
|
92
93
|
"@testing-library/dom": "10.1.0",
|
|
93
94
|
"@testing-library/react": "15.0.7",
|
|
94
95
|
"@testing-library/user-event": "14.5.2",
|