@common_ch/common 1.0.269 → 1.0.270
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type EstimateResult = {
|
|
2
|
+
file: string;
|
|
3
|
+
ext: string;
|
|
4
|
+
sizeMB: number;
|
|
5
|
+
sizeGB: number;
|
|
6
|
+
costPerDayUSD: number;
|
|
7
|
+
costPerMonthUSD: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function estimateStorageCost(filePath: string, storagePricePerGBPerDay?: number): EstimateResult | {
|
|
10
|
+
error: string;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.estimateStorageCost = estimateStorageCost;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
function estimateStorageCost(filePath, storagePricePerGBPerDay = 0.10) {
|
|
10
|
+
var _a;
|
|
11
|
+
if (!fs_1.default.existsSync(filePath)) {
|
|
12
|
+
return { error: "File not found" };
|
|
13
|
+
}
|
|
14
|
+
const fileSizeBytes = fs_1.default.statSync(filePath).size;
|
|
15
|
+
const fileSizeMB = fileSizeBytes / (1024 * 1024);
|
|
16
|
+
const fileSizeGB = fileSizeBytes / (1024 * 1024 * 1024);
|
|
17
|
+
const ext = path_1.default.extname(filePath).toLowerCase();
|
|
18
|
+
const multipliers = {
|
|
19
|
+
".pdf": 2.0,
|
|
20
|
+
".doc": 2.0,
|
|
21
|
+
".docx": 2.0,
|
|
22
|
+
".xls": 2.0,
|
|
23
|
+
".xlsx": 2.0,
|
|
24
|
+
".csv": 1.5,
|
|
25
|
+
".txt": 1.2,
|
|
26
|
+
".json": 1.5,
|
|
27
|
+
".md": 1.2,
|
|
28
|
+
".js": 1.5,
|
|
29
|
+
".ts": 1.5,
|
|
30
|
+
".tsx": 1.5,
|
|
31
|
+
".py": 1.5,
|
|
32
|
+
".java": 1.5,
|
|
33
|
+
".cpp": 1.5,
|
|
34
|
+
".c": 1.5,
|
|
35
|
+
".cs": 1.5,
|
|
36
|
+
".go": 1.5,
|
|
37
|
+
".rb": 1.5,
|
|
38
|
+
".php": 1.5,
|
|
39
|
+
".html": 1.3,
|
|
40
|
+
".css": 1.3,
|
|
41
|
+
".jpg": 1.0,
|
|
42
|
+
".jpeg": 1.0,
|
|
43
|
+
".png": 1.0,
|
|
44
|
+
".gif": 1.0,
|
|
45
|
+
".svg": 1.0,
|
|
46
|
+
".mp3": 1.0,
|
|
47
|
+
".wav": 1.0,
|
|
48
|
+
".mp4": 1.0,
|
|
49
|
+
".mov": 1.0,
|
|
50
|
+
".avi": 1.0,
|
|
51
|
+
};
|
|
52
|
+
const multiplier = (_a = multipliers[ext]) !== null && _a !== void 0 ? _a : 1.0;
|
|
53
|
+
const costPerDay = fileSizeGB * storagePricePerGBPerDay * multiplier;
|
|
54
|
+
const costPerMonth = costPerDay * 30;
|
|
55
|
+
return {
|
|
56
|
+
file: path_1.default.basename(filePath),
|
|
57
|
+
ext,
|
|
58
|
+
sizeMB: Number(fileSizeMB.toFixed(2)),
|
|
59
|
+
sizeGB: Number(fileSizeGB.toFixed(4)),
|
|
60
|
+
costPerDayUSD: Number(costPerDay.toFixed(5)),
|
|
61
|
+
costPerMonthUSD: Number(costPerMonth.toFixed(5)),
|
|
62
|
+
};
|
|
63
|
+
}
|