|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import { randomUUID } from 'crypto';
|
|
|
import { createReadStream, ReadStream } from 'fs';
|
|
import { createReadStream, ReadStream } from 'fs';
|
|
|
import { Readable } from 'stream';
|
|
import { Readable } from 'stream';
|
|
|
|
|
|
|
@@ -110,21 +111,55 @@ const generateAxiosRequestConfigWithTransferKey = (tk: TransferKey, additionalHe
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * Check whether the storage is writable
|
|
|
|
|
+ * @param crowi Crowi instance
|
|
|
|
|
+ * @returns Whether the storage is writable
|
|
|
|
|
+ */
|
|
|
|
|
+const getWritePermission = async(crowi: any): Promise<boolean> => {
|
|
|
|
|
+ const { fileUploadService } = crowi;
|
|
|
|
|
+
|
|
|
|
|
+ let writable = true;
|
|
|
|
|
+ const fileStream = new Readable();
|
|
|
|
|
+ fileStream.push('This file was created during g2g transfer to check write permission. You can safely remove this file.');
|
|
|
|
|
+ fileStream.push(null); // EOF
|
|
|
|
|
+ const attachment = {
|
|
|
|
|
+ fileName: `${randomUUID()}.growi`,
|
|
|
|
|
+ filePath: '',
|
|
|
|
|
+ fileFormat: 'text/plain',
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await fileUploadService.uploadFile(fileStream, attachment);
|
|
|
|
|
+ // TODO: remove tmp file
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ writable = false;
|
|
|
|
|
+ logger.error(err);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return writable;
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* generate GROWIInfo
|
|
* generate GROWIInfo
|
|
|
* @param crowi Crowi instance
|
|
* @param crowi Crowi instance
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
-const generateGROWIInfo = (crowi: any): IDataGROWIInfo => {
|
|
|
|
|
|
|
+const generateGROWIInfo = async(crowi: any): Promise<IDataGROWIInfo> => {
|
|
|
// TODO: add attachment file limit, storage total limit
|
|
// TODO: add attachment file limit, storage total limit
|
|
|
const { configManager } = crowi;
|
|
const { configManager } = crowi;
|
|
|
const userUpperLimit = configManager.getConfig('crowi', 'security:userUpperLimit');
|
|
const userUpperLimit = configManager.getConfig('crowi', 'security:userUpperLimit');
|
|
|
const version = crowi.version;
|
|
const version = crowi.version;
|
|
|
|
|
+ const writable = await getWritePermission(crowi);
|
|
|
|
|
+
|
|
|
const attachmentInfo = {
|
|
const attachmentInfo = {
|
|
|
type: configManager.getConfig('crowi', 'app:fileUploadType'),
|
|
type: configManager.getConfig('crowi', 'app:fileUploadType'),
|
|
|
bucket: undefined,
|
|
bucket: undefined,
|
|
|
customEndpoint: undefined, // for S3
|
|
customEndpoint: undefined, // for S3
|
|
|
uploadNamespace: undefined, // for GCS
|
|
uploadNamespace: undefined, // for GCS
|
|
|
|
|
+ writable,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// put storage location info to check storage identification
|
|
// put storage location info to check storage identification
|