{AWS} Migration to v3
This commit is contained in:
parent
f73d4a3093
commit
abcbd0f8f7
4 changed files with 18196 additions and 42 deletions
18175
package-lock.json
generated
Normal file
18175
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -39,10 +39,11 @@
|
||||||
"prettier": "^2.5.1"
|
"prettier": "^2.5.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@aws-sdk/client-s3": "^3.490.0",
|
||||||
|
"@aws-sdk/lib-storage": "^3.490.0",
|
||||||
"@babel/cli": "^7.17.0",
|
"@babel/cli": "^7.17.0",
|
||||||
"@babel/core": "^7.17.2",
|
"@babel/core": "^7.17.2",
|
||||||
"@babel/preset-env": "^7.16.11",
|
"@babel/preset-env": "^7.16.11",
|
||||||
"aws-sdk": "^2.1110.0",
|
|
||||||
"axios": "^0.26.0",
|
"axios": "^0.26.0",
|
||||||
"connect-ensure-login": "^0.1.1",
|
"connect-ensure-login": "^0.1.1",
|
||||||
"connect-flash": "^0.1.1",
|
"connect-flash": "^0.1.1",
|
||||||
|
|
|
@ -1,28 +1,4 @@
|
||||||
// @use '../node_modules/knacss/sass/knacss.scss';
|
@import '../node_modules/knacss/sass/knacss.scss';
|
||||||
|
|
||||||
// NOYAU
|
|
||||||
@import "../node_modules/knacss/sass/abstracts/variables-sass";
|
|
||||||
@import "../node_modules/knacss/sass/abstracts/mixins-sass";
|
|
||||||
|
|
||||||
@import "../node_modules/knacss/sass/base/reset-base";
|
|
||||||
@import "../node_modules/knacss/sass/base/reset-accessibility";
|
|
||||||
@import "../node_modules/knacss/sass/base/reset-forms";
|
|
||||||
@import "../node_modules/knacss/sass/base/reset-print";
|
|
||||||
@import "../node_modules/knacss/sass/base/layout";
|
|
||||||
|
|
||||||
// UTILITAIRES
|
|
||||||
@import "../node_modules/knacss/sass/utils/utils-global";
|
|
||||||
@import "../node_modules/knacss/sass/utils/utils-font-sizes";
|
|
||||||
@import "../node_modules/knacss/sass/utils/utils-spacers";
|
|
||||||
@import "../node_modules/knacss/sass/utils/grillade";
|
|
||||||
|
|
||||||
// COMPOSANTS (à ajouter au besoin)
|
|
||||||
// @import "../node_modules/knacss/sass/components/button";
|
|
||||||
// @import "components/burger";
|
|
||||||
// @import "../node_modules/knacss/sass/components/checkbox";
|
|
||||||
@import "../node_modules/knacss/sass/components/radio";
|
|
||||||
// @import "../node_modules/knacss/sass/components/select";
|
|
||||||
// @import "components/quote";
|
|
||||||
|
|
||||||
// SPÉCIFIQUE AU SITE
|
// SPÉCIFIQUE AU SITE
|
||||||
@import './fonts';
|
@import './fonts';
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import AWS from "aws-sdk";
|
import { S3Client } from "@aws-sdk/client-s3";
|
||||||
|
import { Upload } from "@aws-sdk/lib-storage";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
@ -10,13 +11,9 @@ import {
|
||||||
s3BaseFolder,
|
s3BaseFolder,
|
||||||
s3Endpoint,
|
s3Endpoint,
|
||||||
s3Bucket,
|
s3Bucket,
|
||||||
s3Signature,
|
// s3Signature,
|
||||||
} from "../config";
|
} from "../config";
|
||||||
|
|
||||||
AWS.config.update({
|
|
||||||
accessKeyId: awsAccessKeyId,
|
|
||||||
secretAccessKey: awsSecretAccessKey,
|
|
||||||
});
|
|
||||||
/**
|
/**
|
||||||
* Fonction permettant de stocker un fichier local sur S3
|
* Fonction permettant de stocker un fichier local sur S3
|
||||||
* @param {String} filename
|
* @param {String} filename
|
||||||
|
@ -27,23 +24,28 @@ AWS.config.update({
|
||||||
*/
|
*/
|
||||||
export const uploadFromFile = async (filename, file, deleteFile = false) => {
|
export const uploadFromFile = async (filename, file, deleteFile = false) => {
|
||||||
const data = await fs.readFileSync(file);
|
const data = await fs.readFileSync(file);
|
||||||
|
|
||||||
const base64data = Buffer.from(data, "binary");
|
const base64data = Buffer.from(data, "binary");
|
||||||
const dest = path.join(s3BaseFolder, filename);
|
const dest = path.join(s3BaseFolder, filename);
|
||||||
|
|
||||||
const s3 = new AWS.S3({
|
const multipartUpload = new Upload({
|
||||||
endpoint: s3Endpoint,
|
client: new S3Client({
|
||||||
signatureVersion: s3Signature,
|
region: "fr-par",
|
||||||
});
|
endpoint: `https://${s3Endpoint}`,
|
||||||
|
credentials: {
|
||||||
await s3
|
accessKeyId: awsAccessKeyId,
|
||||||
.putObject({
|
secretAccessKey: awsSecretAccessKey,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
params: {
|
||||||
Bucket: s3Bucket,
|
Bucket: s3Bucket,
|
||||||
Key: dest,
|
Key: dest,
|
||||||
Body: base64data,
|
Body: base64data,
|
||||||
ACL: "public-read",
|
ACL: "public-read",
|
||||||
})
|
endpoint: s3Endpoint,
|
||||||
.promise();
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await multipartUpload.done();
|
||||||
|
|
||||||
if (deleteFile) {
|
if (deleteFile) {
|
||||||
fs.unlinkSync(file);
|
fs.unlinkSync(file);
|
||||||
|
|
Loading…
Reference in a new issue