fix: local storage base url (#3063)
* fix: local storage base url * fix: test error
This commit is contained in:
parent
57d6a82fcc
commit
379248e5c5
@ -5,7 +5,7 @@ import { FILE_FIELD_NAME, STORAGE_TYPE_LOCAL } from '../constants';
|
|||||||
|
|
||||||
const { LOCAL_STORAGE_BASE_URL, LOCAL_STORAGE_DEST = 'storage/uploads', APP_PORT = '13000' } = process.env;
|
const { LOCAL_STORAGE_BASE_URL, LOCAL_STORAGE_DEST = 'storage/uploads', APP_PORT = '13000' } = process.env;
|
||||||
|
|
||||||
const DEFAULT_LOCAL_BASE_URL = LOCAL_STORAGE_BASE_URL || `http://localhost:${APP_PORT}/storage/uploads`;
|
const DEFAULT_LOCAL_BASE_URL = LOCAL_STORAGE_BASE_URL || `/storage/uploads`;
|
||||||
|
|
||||||
describe('action', () => {
|
describe('action', () => {
|
||||||
let app;
|
let app;
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
import { Repository } from '@nocobase/database';
|
||||||
|
import { Migration } from '@nocobase/server';
|
||||||
|
|
||||||
|
export default class extends Migration {
|
||||||
|
async up() {
|
||||||
|
const result = await this.app.version.satisfies('<0.15.0-alpha.5');
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const r = this.db.getRepository<Repository>('storages');
|
||||||
|
const items = await r.find({
|
||||||
|
filter: {
|
||||||
|
type: 'local',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
for (const item of items) {
|
||||||
|
const baseUrl = item.get('baseUrl');
|
||||||
|
if (baseUrl === '/storage/uploads') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!baseUrl.includes('/storage/uploads')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
item.set('baseUrl', '/storage/uploads');
|
||||||
|
const options = item.get('options');
|
||||||
|
options.documentRoot = 'storage/uploads';
|
||||||
|
item.changed('options', true);
|
||||||
|
item.set('options', options);
|
||||||
|
const [, pathname] = baseUrl.split('/storage/uploads/');
|
||||||
|
if (pathname && item.get('path')) {
|
||||||
|
item.set('path', pathname.replace(/\/$/, '') + '/' + item.get('path'));
|
||||||
|
} else if (pathname) {
|
||||||
|
item.set('path', pathname.replace(/\/$/, ''));
|
||||||
|
}
|
||||||
|
await item.save();
|
||||||
|
}
|
||||||
|
const c = this.db.getCollection('attachments');
|
||||||
|
const table = c.getTableNameWithSchemaAsString();
|
||||||
|
await this.db.sequelize.query(`update ${table} set url = replace(url, 'http://localhost:13000', '')`);
|
||||||
|
}
|
||||||
|
}
|
@ -23,15 +23,13 @@ export default {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
defaults() {
|
defaults() {
|
||||||
const { LOCAL_STORAGE_DEST, LOCAL_STORAGE_BASE_URL, APP_PORT } = process.env;
|
|
||||||
const documentRoot = LOCAL_STORAGE_DEST || 'storage/uploads';
|
|
||||||
return {
|
return {
|
||||||
title: 'Local storage',
|
title: 'Local storage',
|
||||||
type: STORAGE_TYPE_LOCAL,
|
type: STORAGE_TYPE_LOCAL,
|
||||||
name: `local`,
|
name: `local`,
|
||||||
baseUrl: LOCAL_STORAGE_BASE_URL || `http://localhost:${APP_PORT || '13000'}/${documentRoot}`,
|
baseUrl: '/storage/uploads',
|
||||||
options: {
|
options: {
|
||||||
documentRoot,
|
documentRoot: 'storage/uploads',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user