mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 14:38:12 +00:00
booking flow,summtion, approval, contract, mock payemnt and integration to back office, and also add permissions
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Inject, Injectable, Logger } from "@nestjs/common";
|
||||
import { Inject, Injectable, Logger, NotFoundException } from "@nestjs/common";
|
||||
import { ConfigType } from "@nestjs/config";
|
||||
import { Client } from "minio";
|
||||
import { Readable } from "stream";
|
||||
@@ -54,6 +54,30 @@ export class MinioService {
|
||||
return `${protocol}://${this.config.endPoint}:${this.config.port}/${this.bucket}/${objectName}`;
|
||||
}
|
||||
|
||||
getObjectNameFromUrl(value: string): string {
|
||||
const trimmed = value.trim();
|
||||
if (!trimmed) {
|
||||
throw new NotFoundException("File object path is empty");
|
||||
}
|
||||
|
||||
if (!/^https?:\/\//i.test(trimmed)) {
|
||||
return trimmed.replace(/^\/+/, "");
|
||||
}
|
||||
|
||||
const url = new URL(trimmed);
|
||||
const parts = url.pathname.split("/").filter(Boolean);
|
||||
if (parts[0] === this.bucket) {
|
||||
parts.shift();
|
||||
}
|
||||
|
||||
const objectName = parts.join("/");
|
||||
if (!objectName) {
|
||||
throw new NotFoundException("File object path is empty");
|
||||
}
|
||||
|
||||
return objectName;
|
||||
}
|
||||
|
||||
async deleteFile(objectName: string): Promise<void> {
|
||||
try {
|
||||
await this.client.removeObject(this.bucket, objectName);
|
||||
|
||||
Reference in New Issue
Block a user