mirror of
https://github.com/strapi/strapi.git
synced 2025-11-13 16:52:18 +00:00
feat(menu-logo): added upload feature
This commit is contained in:
parent
a298c243db
commit
3451aceaf5
@ -51,7 +51,9 @@ module.exports = {
|
|||||||
|
|
||||||
await validateUpdateProjectSettings(files);
|
await validateUpdateProjectSettings(files);
|
||||||
|
|
||||||
console.log(files);
|
const uploadedFiles = await getService('project-settings').uploadProjectSettingsFiles(files);
|
||||||
|
|
||||||
|
console.log(uploadedFiles);
|
||||||
},
|
},
|
||||||
|
|
||||||
async information() {
|
async information() {
|
||||||
|
|||||||
@ -13,4 +13,5 @@ module.exports = {
|
|||||||
auth: require('./auth'),
|
auth: require('./auth'),
|
||||||
action: require('./action'),
|
action: require('./action'),
|
||||||
'api-token': require('./api-token'),
|
'api-token': require('./api-token'),
|
||||||
|
'project-settings': require('./project-settings'),
|
||||||
};
|
};
|
||||||
|
|||||||
38
packages/core/admin/server/services/project-settings.js
Normal file
38
packages/core/admin/server/services/project-settings.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const { transform } = require('lodash');
|
||||||
|
|
||||||
|
const getFormatedFileData = data => ({
|
||||||
|
path: data.path,
|
||||||
|
...strapi
|
||||||
|
.plugin('upload')
|
||||||
|
.service('upload')
|
||||||
|
.formatFileInfo({
|
||||||
|
filename: data.name,
|
||||||
|
type: data.type,
|
||||||
|
size: data.size,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const uploadProjectSettingsFiles = async files => {
|
||||||
|
const formatedFilesData = transform(files, (result, value, key) => {
|
||||||
|
if (value) {
|
||||||
|
result[key] = getFormatedFileData(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.values(formatedFilesData).map(data =>
|
||||||
|
// Do not await to upload asynchronously
|
||||||
|
strapi.plugin('upload').provider.uploadStream({
|
||||||
|
...data,
|
||||||
|
stream: fs.createReadStream(data.path),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return formatedFilesData;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
uploadProjectSettingsFiles,
|
||||||
|
};
|
||||||
2
packages/core/admin/server/utils/index.d.ts
vendored
2
packages/core/admin/server/utils/index.d.ts
vendored
@ -6,6 +6,7 @@ import * as metrics from '../services/metrics';
|
|||||||
import * as token from '../services/token';
|
import * as token from '../services/token';
|
||||||
import * as auth from '../services/auth';
|
import * as auth from '../services/auth';
|
||||||
import * as apiToken from '../services/api-token';
|
import * as apiToken from '../services/api-token';
|
||||||
|
import * as projectSettings from '../services/project-settings';
|
||||||
|
|
||||||
type S = {
|
type S = {
|
||||||
role: typeof role;
|
role: typeof role;
|
||||||
@ -16,6 +17,7 @@ type S = {
|
|||||||
auth: typeof auth;
|
auth: typeof auth;
|
||||||
metrics: typeof metrics;
|
metrics: typeof metrics;
|
||||||
'api-token': typeof apiToken;
|
'api-token': typeof apiToken;
|
||||||
|
'project-settings': typeof projectSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getService<T extends keyof S>(name: T): S[T];
|
export function getService<T extends keyof S>(name: T): S[T];
|
||||||
|
|||||||
@ -8,7 +8,7 @@ const ALLOWED_LOGO_FILE_TYPES = ['image/jpeg', 'image/png', 'image/svg+xml'];
|
|||||||
const updateProjectSettings = yup
|
const updateProjectSettings = yup
|
||||||
.object({
|
.object({
|
||||||
menuLogo: yup.object({
|
menuLogo: yup.object({
|
||||||
name: yup.string().max(255),
|
name: yup.string(),
|
||||||
type: yup.string().oneOf(ALLOWED_LOGO_FILE_TYPES),
|
type: yup.string().oneOf(ALLOWED_LOGO_FILE_TYPES),
|
||||||
size: yup.number().max(MAX_LOGO_SIZE),
|
size: yup.number().max(MAX_LOGO_SIZE),
|
||||||
}),
|
}),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user