|
@@ -13,6 +13,10 @@ import urljoin from 'url-join';
|
|
|
|
|
|
|
|
import loggerFactory from '~/utils/logger';
|
|
import loggerFactory from '~/utils/logger';
|
|
|
|
|
|
|
|
|
|
+import { configManager } from '../config-manager';
|
|
|
|
|
+
|
|
|
|
|
+import { AbstractFileUploader, SaveFileParam } from './file-uploader';
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const logger = loggerFactory('growi:service:fileUploaderAws');
|
|
const logger = loggerFactory('growi:service:fileUploaderAws');
|
|
|
|
|
|
|
@@ -37,10 +41,40 @@ type AwsConfig = {
|
|
|
forcePathStyle?: boolean
|
|
forcePathStyle?: boolean
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+class AwsFileUploader extends AbstractFileUploader {
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritdoc
|
|
|
|
|
+ */
|
|
|
|
|
+ override isValidUploadSettings(): boolean {
|
|
|
|
|
+ throw new Error('Method not implemented.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritdoc
|
|
|
|
|
+ */
|
|
|
|
|
+ override saveFile(param: SaveFileParam) {
|
|
|
|
|
+ throw new Error('Method not implemented.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritdoc
|
|
|
|
|
+ */
|
|
|
|
|
+ override deleteFiles() {
|
|
|
|
|
+ throw new Error('Method not implemented.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @inheritdoc
|
|
|
|
|
+ */
|
|
|
|
|
+ override respond(res: Response, attachment: Response): void {
|
|
|
|
|
+ throw new Error('Method not implemented.');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
module.exports = (crowi) => {
|
|
module.exports = (crowi) => {
|
|
|
- const Uploader = require('./uploader');
|
|
|
|
|
- const { configManager } = crowi;
|
|
|
|
|
- const lib = new Uploader(crowi);
|
|
|
|
|
|
|
+ const lib = new AwsFileUploader(crowi);
|
|
|
|
|
|
|
|
const getAwsConfig = (): AwsConfig => {
|
|
const getAwsConfig = (): AwsConfig => {
|
|
|
return {
|
|
return {
|
|
@@ -100,7 +134,7 @@ module.exports = (crowi) => {
|
|
|
return !configManager.getConfig('crowi', 'aws:referenceFileWithRelayMode');
|
|
return !configManager.getConfig('crowi', 'aws:referenceFileWithRelayMode');
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- lib.respond = async function(res, attachment) {
|
|
|
|
|
|
|
+ (lib as any).respond = async function(res, attachment) {
|
|
|
if (!lib.getIsUploadable()) {
|
|
if (!lib.getIsUploadable()) {
|
|
|
throw new Error('AWS is not configured.');
|
|
throw new Error('AWS is not configured.');
|
|
|
}
|
|
}
|
|
@@ -134,12 +168,12 @@ module.exports = (crowi) => {
|
|
|
|
|
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- lib.deleteFile = async function(attachment) {
|
|
|
|
|
|
|
+ (lib as any).deleteFile = async function(attachment) {
|
|
|
const filePath = getFilePathOnStorage(attachment);
|
|
const filePath = getFilePathOnStorage(attachment);
|
|
|
- return lib.deleteFileByFilePath(filePath);
|
|
|
|
|
|
|
+ return (lib as any).deleteFileByFilePath(filePath);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- lib.deleteFiles = async function(attachments) {
|
|
|
|
|
|
|
+ (lib as any).deleteFiles = async function(attachments) {
|
|
|
if (!lib.getIsUploadable()) {
|
|
if (!lib.getIsUploadable()) {
|
|
|
throw new Error('AWS is not configured.');
|
|
throw new Error('AWS is not configured.');
|
|
|
}
|
|
}
|
|
@@ -157,7 +191,7 @@ module.exports = (crowi) => {
|
|
|
return s3.send(new DeleteObjectsCommand(totalParams));
|
|
return s3.send(new DeleteObjectsCommand(totalParams));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- lib.deleteFileByFilePath = async function(filePath) {
|
|
|
|
|
|
|
+ (lib as any).deleteFileByFilePath = async function(filePath) {
|
|
|
if (!lib.getIsUploadable()) {
|
|
if (!lib.getIsUploadable()) {
|
|
|
throw new Error('AWS is not configured.');
|
|
throw new Error('AWS is not configured.');
|
|
|
}
|
|
}
|
|
@@ -179,7 +213,7 @@ module.exports = (crowi) => {
|
|
|
return s3.send(new DeleteObjectCommand(params));
|
|
return s3.send(new DeleteObjectCommand(params));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- lib.uploadAttachment = async function(fileStream, attachment) {
|
|
|
|
|
|
|
+ (lib as any).uploadAttachment = async function(fileStream, attachment) {
|
|
|
if (!lib.getIsUploadable()) {
|
|
if (!lib.getIsUploadable()) {
|
|
|
throw new Error('AWS is not configured.');
|
|
throw new Error('AWS is not configured.');
|
|
|
}
|
|
}
|
|
@@ -216,7 +250,7 @@ module.exports = (crowi) => {
|
|
|
return s3.send(new PutObjectCommand(params));
|
|
return s3.send(new PutObjectCommand(params));
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- lib.findDeliveryFile = async function(attachment) {
|
|
|
|
|
|
|
+ (lib as any).findDeliveryFile = async function(attachment) {
|
|
|
if (!lib.getIsReadable()) {
|
|
if (!lib.getIsReadable()) {
|
|
|
throw new Error('AWS is not configured.');
|
|
throw new Error('AWS is not configured.');
|
|
|
}
|
|
}
|
|
@@ -249,7 +283,7 @@ module.exports = (crowi) => {
|
|
|
return stream;
|
|
return stream;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- lib.checkLimit = async function(uploadFileSize) {
|
|
|
|
|
|
|
+ (lib as any).checkLimit = async function(uploadFileSize) {
|
|
|
const maxFileSize = configManager.getConfig('crowi', 'app:maxFileSize');
|
|
const maxFileSize = configManager.getConfig('crowi', 'app:maxFileSize');
|
|
|
const totalLimit = configManager.getConfig('crowi', 'app:fileUploadTotalLimit');
|
|
const totalLimit = configManager.getConfig('crowi', 'app:fileUploadTotalLimit');
|
|
|
return lib.doCheckLimit(uploadFileSize, maxFileSize, totalLimit);
|
|
return lib.doCheckLimit(uploadFileSize, maxFileSize, totalLimit);
|
|
@@ -258,7 +292,7 @@ module.exports = (crowi) => {
|
|
|
/**
|
|
/**
|
|
|
* List files in storage
|
|
* List files in storage
|
|
|
*/
|
|
*/
|
|
|
- lib.listFiles = async function() {
|
|
|
|
|
|
|
+ (lib as any).listFiles = async function() {
|
|
|
if (!lib.getIsReadable()) {
|
|
if (!lib.getIsReadable()) {
|
|
|
throw new Error('AWS is not configured.');
|
|
throw new Error('AWS is not configured.');
|
|
|
}
|
|
}
|