diff --git a/packages/core/client/src/schema-component/antd/upload/Upload.tsx b/packages/core/client/src/schema-component/antd/upload/Upload.tsx index 241f73e0df..4ae5cc2da1 100644 --- a/packages/core/client/src/schema-component/antd/upload/Upload.tsx +++ b/packages/core/client/src/schema-component/antd/upload/Upload.tsx @@ -389,7 +389,7 @@ export function Uploader({ rules, ...props }: UploadProps) { if (pendingFiles.length) { setUploadedList(valueList); } else { - onChange?.([...value, ...valueList]); + onChange?.([...(value || []), ...valueList]); setUploadedList([]); } } diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/client/templates/file.ts b/packages/plugins/@nocobase/plugin-file-manager/src/client/templates/file.ts index 6b9e36b082..f943aefe38 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/client/templates/file.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/client/templates/file.ts @@ -104,6 +104,7 @@ export class FileCollectionTemplate extends CollectionTemplate { type: 'string', name: 'url', deletable: false, + length: 1024, uiSchema: { type: 'string', title: `{{t("URL")}}`, diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/server/collections/attachments.ts b/packages/plugins/@nocobase/plugin-file-manager/src/server/collections/attachments.ts index 92cb5308b1..48c88761ab 100644 --- a/packages/plugins/@nocobase/plugin-file-manager/src/server/collections/attachments.ts +++ b/packages/plugins/@nocobase/plugin-file-manager/src/server/collections/attachments.ts @@ -70,6 +70,7 @@ export default defineCollection({ comment: '网络访问地址', type: 'string', name: 'url', + length: 1024, // formula: '{{ storage.baseUrl }}{{ path }}/{{ filename }}' }, ], diff --git a/packages/plugins/@nocobase/plugin-file-manager/src/server/migrations/20250224112112-increase-url-length.ts b/packages/plugins/@nocobase/plugin-file-manager/src/server/migrations/20250224112112-increase-url-length.ts new file mode 100644 index 0000000000..d21e843f4d --- /dev/null +++ b/packages/plugins/@nocobase/plugin-file-manager/src/server/migrations/20250224112112-increase-url-length.ts @@ -0,0 +1,55 @@ +/** + * This file is part of the NocoBase (R) project. + * Copyright (c) 2020-2024 NocoBase Co., Ltd. + * Authors: NocoBase Team. + * + * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License. + * For more information, please refer to: https://www.nocobase.com/agreement. + */ + +import { DataTypes } from 'sequelize'; +import { Migration } from '@nocobase/server'; + +export default class extends Migration { + on = 'afterLoad'; // 'beforeLoad' or 'afterLoad' + appVersion = '<1.5.14'; + + async up() { + const queryInterface = this.db.sequelize.getQueryInterface(); + const CollectionRepo = this.db.getRepository('collections'); + const FieldRepo = this.db.getRepository('fields'); + await this.db.sequelize.transaction(async (transaction) => { + const collections = await CollectionRepo.find({ + filter: { + 'options.template': 'file', + }, + transaction, + }); + collections.push({ + name: 'attachments', + }); + for (const item of collections) { + const collection = this.db.getCollection(item.name) || this.db.collection(item); + const tableName = collection.getTableNameWithSchema(); + await queryInterface.changeColumn( + tableName, + 'url', + { + type: DataTypes.STRING(1024), + }, + { transaction }, + ); + await FieldRepo.update({ + filter: { + collectionName: item.name, + name: 'url', + }, + values: { + length: 1024, + }, + transaction, + }); + } + }); + } +}