Finished
This commit is contained in:
parent
ecc0342155
commit
dffe813968
@ -130,6 +130,18 @@ export class BackendVariables {
|
||||
@IsNotEmpty()
|
||||
public readonly SMS_FACTOR_TOKEN!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly SCW_ACCESS_KEY_ID!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly SCW_ACCESS_KEY_SECRET!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly SCW_BUCKET_ENDPOINT!: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
public readonly SCW_BUCKET_NAME!: string;
|
||||
|
||||
public constructor() {
|
||||
dotenv.config();
|
||||
this.DATABASE_PORT = process.env["DATABASE_PORT"]!;
|
||||
@ -174,6 +186,10 @@ export class BackendVariables {
|
||||
this.OVH_CONSUMER_KEY = process.env["OVH_CONSUMER_KEY"]!;
|
||||
this.OVH_SMS_SERVICE_NAME = process.env["OVH_SMS_SERVICE_NAME"]!;
|
||||
this.SMS_FACTOR_TOKEN = process.env["SMS_FACTOR_TOKEN"]!;
|
||||
this.SCW_ACCESS_KEY_ID = process.env["SCW_ACCESS_KEY_ID"]!;
|
||||
this.SCW_ACCESS_KEY_SECRET = process.env["SCW_ACCESS_KEY_SECRET"]!;
|
||||
this.SCW_BUCKET_ENDPOINT = process.env["SCW_BUCKET_ENDPOINT"]!;
|
||||
this.SCW_BUCKET_NAME = process.env["SCW_BUCKET_NAME"]!;
|
||||
}
|
||||
public async validate(groups?: string[]) {
|
||||
const validationOptions = groups ? { groups } : undefined;
|
||||
|
@ -121,7 +121,6 @@ export default class IdNotService extends BaseService {
|
||||
code: code,
|
||||
grant_type: "authorization_code",
|
||||
});
|
||||
console.log(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query.toString());
|
||||
|
||||
const token = await fetch(this.variables.IDNOT_BASE_URL + this.variables.IDNOT_CONNEXION_URL + "?" + query, { method: "POST" });
|
||||
if(token.status !== 200) console.error(await token.text());
|
||||
|
@ -4,29 +4,29 @@ import * as AWS from "aws-sdk";
|
||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||
import path from "path";
|
||||
|
||||
// Configure the AWS SDK for Scaleway
|
||||
const s3 = new AWS.S3({
|
||||
accessKeyId: "SCWZ39ZVQWXFC7HA0647",
|
||||
secretAccessKey: "59bcf27d-bee3-4d14-8b4d-03fd6a8be6cd",
|
||||
endpoint: "https://lecoffre-bucket.s3.fr-par.scw.cloud", // Use the appropriate Scaleway endpoint
|
||||
s3ForcePathStyle: true, // Needed for Scaleway's S3-compatible API
|
||||
signatureVersion: "v4",
|
||||
});
|
||||
|
||||
@Service()
|
||||
export default class OfficerRibService extends BaseService {
|
||||
private readonly s3: AWS.S3;
|
||||
constructor(private variables: BackendVariables) {
|
||||
super();
|
||||
|
||||
// Configure the AWS SDK for Scaleway
|
||||
this.s3 = new AWS.S3({
|
||||
accessKeyId: this.variables.SCW_ACCESS_KEY_ID,
|
||||
secretAccessKey: this.variables.SCW_ACCESS_KEY_SECRET,
|
||||
endpoint: this.variables.SCW_BUCKET_ENDPOINT, // Use the appropriate Scaleway endpoint
|
||||
s3ForcePathStyle: true, // Needed for Scaleway's S3-compatible API
|
||||
signatureVersion: "v4",
|
||||
});
|
||||
}
|
||||
|
||||
public async getByUid(uid: string, fileName: string) {
|
||||
const key = path.join(this.variables.ENV, uid, fileName);
|
||||
|
||||
|
||||
|
||||
return new Promise<AWS.S3.GetObjectOutput>(async (resolve, reject) => {
|
||||
s3.getObject(
|
||||
this.s3.getObject(
|
||||
{
|
||||
Bucket: "lecoffre-bucket",
|
||||
Bucket: this.variables.SCW_BUCKET_NAME,
|
||||
Key: key,
|
||||
},
|
||||
function (err, data) {
|
||||
@ -34,21 +34,21 @@ export default class OfficerRibService extends BaseService {
|
||||
resolve(data);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public async createOrUpdate(officeId: string, file: Express.Multer.File) {
|
||||
const key = path.join(this.variables.ENV, officeId, file.originalname);
|
||||
|
||||
const uploadParams = {
|
||||
Bucket: "lecoffre-bucket",
|
||||
Bucket: this.variables.SCW_BUCKET_NAME,
|
||||
Key: key, // Example: 'example.txt'
|
||||
Body: file.buffer, // Example: fs.createReadStream('/path/to/file')
|
||||
ACL: "public-read", // Optional: Set the ACL if needed
|
||||
};
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
s3.putObject(uploadParams, function (err, data) {
|
||||
this.s3.putObject(uploadParams, function (err, data) {
|
||||
if (err) return reject(err);
|
||||
resolve(`https://lecoffre-bucket.s3.fr-par.scw.cloud/lecoffre-bucket/${key}`);
|
||||
});
|
||||
@ -59,9 +59,9 @@ export default class OfficerRibService extends BaseService {
|
||||
const key = path.join(this.variables.ENV, officeId, fileName);
|
||||
|
||||
return new Promise<AWS.S3.GetObjectOutput>(async (resolve, reject) => {
|
||||
s3.getObject(
|
||||
this.s3.getObject(
|
||||
{
|
||||
Bucket: "lecoffre-bucket",
|
||||
Bucket: this.variables.SCW_BUCKET_NAME,
|
||||
Key: key,
|
||||
},
|
||||
function (err, data) {
|
||||
@ -69,6 +69,6 @@ export default class OfficerRibService extends BaseService {
|
||||
resolve(data);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user