mirror of
https://github.com/plankanban/planka.git
synced 2025-07-31 19:19:44 +02:00
support project background + user avatar
This commit is contained in:
parent
84b0f91b44
commit
e84a2837ab
13 changed files with 223 additions and 46 deletions
|
@ -53,19 +53,26 @@ module.exports = {
|
|||
try {
|
||||
const type = attachment.type || 'local';
|
||||
if (type === 's3') {
|
||||
const client = await sails.helpers.attachments.getSimpleStorageServiceClient();
|
||||
const client = await sails.helpers.utils.getSimpleStorageServiceClient();
|
||||
if (client) {
|
||||
const file1 = `${attachment.dirname}/${attachment.filename}`;
|
||||
const file2 = `${attachment.dirname}/thumbnails/cover-256.png`;
|
||||
await client.delete({ Key: file1 });
|
||||
await client.delete({ Key: file2 });
|
||||
if (attachment.url) {
|
||||
const parsedUrl = new URL(attachment.url);
|
||||
await client.delete({ Key: parsedUrl.pathname.replace(/^\/+/, '') });
|
||||
}
|
||||
if (attachment.thumb) {
|
||||
const parsedUrl = new URL(attachment.thumb);
|
||||
await client.delete({ Key: parsedUrl.pathname.replace(/^\/+/, '') });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rimraf.sync(path.join(sails.config.custom.attachmentsPath, attachment.dirname));
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
}
|
||||
try {
|
||||
rimraf.sync(path.join(sails.config.custom.attachmentsPath, attachment.dirname));
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
sails.sockets.broadcast(
|
||||
`board:${inputs.board.id}`,
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
const AWS = require('aws-sdk');
|
||||
|
||||
class S3Client {
|
||||
constructor(options) {
|
||||
AWS.config.update({
|
||||
accessKeyId: options.accessKeyId,
|
||||
secretAccessKey: options.secretAccessKey,
|
||||
region: options.region,
|
||||
});
|
||||
this.bucket = options.bucket;
|
||||
this.client = new AWS.S3({
|
||||
endpoint: options.endpoint,
|
||||
});
|
||||
}
|
||||
|
||||
upload({ Key, Body, ContentType }) {
|
||||
return this.client
|
||||
.upload({
|
||||
Bucket: this.bucket,
|
||||
Key,
|
||||
Body,
|
||||
ContentType,
|
||||
ACL: 'public-read',
|
||||
})
|
||||
.promise();
|
||||
}
|
||||
|
||||
delete({ Key }) {
|
||||
return this.client
|
||||
.deleteObject({
|
||||
Bucket: this.bucket,
|
||||
Key,
|
||||
})
|
||||
.promise();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fn() {
|
||||
if (sails.config.custom.attachmentsS3) {
|
||||
return new S3Client(sails.config.custom.attachmentsS3);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
};
|
|
@ -23,11 +23,11 @@ module.exports = {
|
|||
const rootPath = path.join(sails.config.custom.attachmentsPath, dirname);
|
||||
const filePath = path.join(rootPath, filename);
|
||||
|
||||
if (sails.config.custom.attachmentsS3) {
|
||||
const client = await sails.helpers.attachments.getSimpleStorageServiceClient();
|
||||
if (sails.config.custom.s3Config) {
|
||||
const client = await sails.helpers.utils.getSimpleStorageServiceClient();
|
||||
const s3Image = await client.upload({
|
||||
Body: fs.createReadStream(inputs.file.fd),
|
||||
Key: `${dirname}/${filename}`,
|
||||
Key: `attachments/${dirname}/${filename}`,
|
||||
ContentType: inputs.file.type,
|
||||
});
|
||||
|
||||
|
@ -72,7 +72,7 @@ module.exports = {
|
|||
)
|
||||
.toBuffer();
|
||||
const s3Thumb = await client.upload({
|
||||
Key: `${dirname}/thumbnails/cover-256.${thumbnailsExtension}`,
|
||||
Key: `attachments/${dirname}/thumbnails/cover-256.${thumbnailsExtension}`,
|
||||
Body: resizeBuffer,
|
||||
ContentType: inputs.file.type,
|
||||
});
|
||||
|
@ -83,6 +83,12 @@ module.exports = {
|
|||
}
|
||||
}
|
||||
|
||||
try {
|
||||
rimraf.sync(inputs.file.fd);
|
||||
} catch (error) {
|
||||
console.warn(error.stack); // eslint-disable-line no-console
|
||||
}
|
||||
|
||||
return fileData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue