@react-pakistan/util-functions 1.22.69 → 1.22.70
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable no-console */
|
|
2
3
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
4
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
5
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const removeDataImagePrefix: (base64: string) => string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeDataImagePrefix = void 0;
|
|
4
|
+
const removeDataImagePrefix = (base64) => base64
|
|
5
|
+
.replace(/data:image\/jpeg;base64,/i, '');
|
|
6
|
+
exports.removeDataImagePrefix = removeDataImagePrefix;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.uploadImageToSupabase = void 0;
|
|
14
|
+
const remove_data_image_prefix_1 = require("./remove-data-image-prefix");
|
|
15
|
+
const uploadImageToSupabase = (_a) => __awaiter(void 0, [_a], void 0, function* ({ blob, supabase, fileRef, contentType, }) {
|
|
16
|
+
const base64StringWithoutPrefix = (0, remove_data_image_prefix_1.removeDataImagePrefix)(blob);
|
|
17
|
+
const buffer = Buffer.from(base64StringWithoutPrefix, 'base64');
|
|
18
|
+
const { data, error } = yield supabase.storage
|
|
19
|
+
.from(process.env.NEXT_PUBLIC_SUPABASE_PRIVATE_BUCKET)
|
|
20
|
+
.upload(fileRef, buffer, {
|
|
21
|
+
upsert: false,
|
|
22
|
+
cacheControl: process.env.NEXT_PUBLIC_SUPABASE_CACHE_CONTROL,
|
|
23
|
+
contentType,
|
|
24
|
+
});
|
|
25
|
+
if (error) {
|
|
26
|
+
return error;
|
|
27
|
+
}
|
|
28
|
+
return data;
|
|
29
|
+
});
|
|
30
|
+
exports.uploadImageToSupabase = uploadImageToSupabase;
|