Files
ANDJJJJJJ/server/node_modules/node-appwrite/dist/services/storage.mjs

608 lines
18 KiB
JavaScript

import { AppwriteException } from '../client.mjs';
// src/services/storage.ts
var Storage = class {
constructor(client) {
this.client = client;
}
listBuckets(paramsOrFirst, ...rest) {
let params;
if (!paramsOrFirst || paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
queries: paramsOrFirst,
search: rest[0],
total: rest[1]
};
}
const queries = params.queries;
const search = params.search;
const total = params.total;
const apiPath = "/storage/buckets";
const payload = {};
if (typeof queries !== "undefined") {
payload["queries"] = queries;
}
if (typeof search !== "undefined") {
payload["search"] = search;
}
if (typeof total !== "undefined") {
payload["total"] = total;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload
);
}
createBucket(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
name: rest[0],
permissions: rest[1],
fileSecurity: rest[2],
enabled: rest[3],
maximumFileSize: rest[4],
allowedFileExtensions: rest[5],
compression: rest[6],
encryption: rest[7],
antivirus: rest[8],
transformations: rest[9]
};
}
const bucketId = params.bucketId;
const name = params.name;
const permissions = params.permissions;
const fileSecurity = params.fileSecurity;
const enabled = params.enabled;
const maximumFileSize = params.maximumFileSize;
const allowedFileExtensions = params.allowedFileExtensions;
const compression = params.compression;
const encryption = params.encryption;
const antivirus = params.antivirus;
const transformations = params.transformations;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof name === "undefined") {
throw new AppwriteException('Missing required parameter: "name"');
}
const apiPath = "/storage/buckets";
const payload = {};
if (typeof bucketId !== "undefined") {
payload["bucketId"] = bucketId;
}
if (typeof name !== "undefined") {
payload["name"] = name;
}
if (typeof permissions !== "undefined") {
payload["permissions"] = permissions;
}
if (typeof fileSecurity !== "undefined") {
payload["fileSecurity"] = fileSecurity;
}
if (typeof enabled !== "undefined") {
payload["enabled"] = enabled;
}
if (typeof maximumFileSize !== "undefined") {
payload["maximumFileSize"] = maximumFileSize;
}
if (typeof allowedFileExtensions !== "undefined") {
payload["allowedFileExtensions"] = allowedFileExtensions;
}
if (typeof compression !== "undefined") {
payload["compression"] = compression;
}
if (typeof encryption !== "undefined") {
payload["encryption"] = encryption;
}
if (typeof antivirus !== "undefined") {
payload["antivirus"] = antivirus;
}
if (typeof transformations !== "undefined") {
payload["transformations"] = transformations;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"post",
uri,
apiHeaders,
payload
);
}
getBucket(paramsOrFirst) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst
};
}
const bucketId = params.bucketId;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
const apiPath = "/storage/buckets/{bucketId}".replace("{bucketId}", bucketId);
const payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload
);
}
updateBucket(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
name: rest[0],
permissions: rest[1],
fileSecurity: rest[2],
enabled: rest[3],
maximumFileSize: rest[4],
allowedFileExtensions: rest[5],
compression: rest[6],
encryption: rest[7],
antivirus: rest[8],
transformations: rest[9]
};
}
const bucketId = params.bucketId;
const name = params.name;
const permissions = params.permissions;
const fileSecurity = params.fileSecurity;
const enabled = params.enabled;
const maximumFileSize = params.maximumFileSize;
const allowedFileExtensions = params.allowedFileExtensions;
const compression = params.compression;
const encryption = params.encryption;
const antivirus = params.antivirus;
const transformations = params.transformations;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof name === "undefined") {
throw new AppwriteException('Missing required parameter: "name"');
}
const apiPath = "/storage/buckets/{bucketId}".replace("{bucketId}", bucketId);
const payload = {};
if (typeof name !== "undefined") {
payload["name"] = name;
}
if (typeof permissions !== "undefined") {
payload["permissions"] = permissions;
}
if (typeof fileSecurity !== "undefined") {
payload["fileSecurity"] = fileSecurity;
}
if (typeof enabled !== "undefined") {
payload["enabled"] = enabled;
}
if (typeof maximumFileSize !== "undefined") {
payload["maximumFileSize"] = maximumFileSize;
}
if (typeof allowedFileExtensions !== "undefined") {
payload["allowedFileExtensions"] = allowedFileExtensions;
}
if (typeof compression !== "undefined") {
payload["compression"] = compression;
}
if (typeof encryption !== "undefined") {
payload["encryption"] = encryption;
}
if (typeof antivirus !== "undefined") {
payload["antivirus"] = antivirus;
}
if (typeof transformations !== "undefined") {
payload["transformations"] = transformations;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"put",
uri,
apiHeaders,
payload
);
}
deleteBucket(paramsOrFirst) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst
};
}
const bucketId = params.bucketId;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
const apiPath = "/storage/buckets/{bucketId}".replace("{bucketId}", bucketId);
const payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"delete",
uri,
apiHeaders,
payload
);
}
listFiles(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
queries: rest[0],
search: rest[1],
total: rest[2]
};
}
const bucketId = params.bucketId;
const queries = params.queries;
const search = params.search;
const total = params.total;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
const apiPath = "/storage/buckets/{bucketId}/files".replace("{bucketId}", bucketId);
const payload = {};
if (typeof queries !== "undefined") {
payload["queries"] = queries;
}
if (typeof search !== "undefined") {
payload["search"] = search;
}
if (typeof total !== "undefined") {
payload["total"] = total;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload
);
}
createFile(paramsOrFirst, ...rest) {
let params;
let onProgress;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
onProgress = paramsOrFirst == null ? void 0 : paramsOrFirst.onProgress;
} else {
params = {
bucketId: paramsOrFirst,
fileId: rest[0],
file: rest[1],
permissions: rest[2]
};
onProgress = rest[3];
}
const bucketId = params.bucketId;
const fileId = params.fileId;
const file = params.file;
const permissions = params.permissions;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new AppwriteException('Missing required parameter: "fileId"');
}
if (typeof file === "undefined") {
throw new AppwriteException('Missing required parameter: "file"');
}
const apiPath = "/storage/buckets/{bucketId}/files".replace("{bucketId}", bucketId);
const payload = {};
if (typeof fileId !== "undefined") {
payload["fileId"] = fileId;
}
if (typeof file !== "undefined") {
payload["file"] = file;
}
if (typeof permissions !== "undefined") {
payload["permissions"] = permissions;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "multipart/form-data"
};
return this.client.chunkedUpload(
"post",
uri,
apiHeaders,
payload,
onProgress
);
}
getFile(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
fileId: rest[0]
};
}
const bucketId = params.bucketId;
const fileId = params.fileId;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/storage/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload
);
}
updateFile(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
fileId: rest[0],
name: rest[1],
permissions: rest[2]
};
}
const bucketId = params.bucketId;
const fileId = params.fileId;
const name = params.name;
const permissions = params.permissions;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/storage/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
if (typeof name !== "undefined") {
payload["name"] = name;
}
if (typeof permissions !== "undefined") {
payload["permissions"] = permissions;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"put",
uri,
apiHeaders,
payload
);
}
deleteFile(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
fileId: rest[0]
};
}
const bucketId = params.bucketId;
const fileId = params.fileId;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/storage/buckets/{bucketId}/files/{fileId}".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {
"content-type": "application/json"
};
return this.client.call(
"delete",
uri,
apiHeaders,
payload
);
}
getFileDownload(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
fileId: rest[0],
token: rest[1]
};
}
const bucketId = params.bucketId;
const fileId = params.fileId;
const token = params.token;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/storage/buckets/{bucketId}/files/{fileId}/download".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
if (typeof token !== "undefined") {
payload["token"] = token;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload,
"arrayBuffer"
);
}
getFilePreview(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
fileId: rest[0],
width: rest[1],
height: rest[2],
gravity: rest[3],
quality: rest[4],
borderWidth: rest[5],
borderColor: rest[6],
borderRadius: rest[7],
opacity: rest[8],
rotation: rest[9],
background: rest[10],
output: rest[11],
token: rest[12]
};
}
const bucketId = params.bucketId;
const fileId = params.fileId;
const width = params.width;
const height = params.height;
const gravity = params.gravity;
const quality = params.quality;
const borderWidth = params.borderWidth;
const borderColor = params.borderColor;
const borderRadius = params.borderRadius;
const opacity = params.opacity;
const rotation = params.rotation;
const background = params.background;
const output = params.output;
const token = params.token;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/storage/buckets/{bucketId}/files/{fileId}/preview".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
if (typeof width !== "undefined") {
payload["width"] = width;
}
if (typeof height !== "undefined") {
payload["height"] = height;
}
if (typeof gravity !== "undefined") {
payload["gravity"] = gravity;
}
if (typeof quality !== "undefined") {
payload["quality"] = quality;
}
if (typeof borderWidth !== "undefined") {
payload["borderWidth"] = borderWidth;
}
if (typeof borderColor !== "undefined") {
payload["borderColor"] = borderColor;
}
if (typeof borderRadius !== "undefined") {
payload["borderRadius"] = borderRadius;
}
if (typeof opacity !== "undefined") {
payload["opacity"] = opacity;
}
if (typeof rotation !== "undefined") {
payload["rotation"] = rotation;
}
if (typeof background !== "undefined") {
payload["background"] = background;
}
if (typeof output !== "undefined") {
payload["output"] = output;
}
if (typeof token !== "undefined") {
payload["token"] = token;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload,
"arrayBuffer"
);
}
getFileView(paramsOrFirst, ...rest) {
let params;
if (paramsOrFirst && typeof paramsOrFirst === "object" && !Array.isArray(paramsOrFirst)) {
params = paramsOrFirst || {};
} else {
params = {
bucketId: paramsOrFirst,
fileId: rest[0],
token: rest[1]
};
}
const bucketId = params.bucketId;
const fileId = params.fileId;
const token = params.token;
if (typeof bucketId === "undefined") {
throw new AppwriteException('Missing required parameter: "bucketId"');
}
if (typeof fileId === "undefined") {
throw new AppwriteException('Missing required parameter: "fileId"');
}
const apiPath = "/storage/buckets/{bucketId}/files/{fileId}/view".replace("{bucketId}", bucketId).replace("{fileId}", fileId);
const payload = {};
if (typeof token !== "undefined") {
payload["token"] = token;
}
const uri = new URL(this.client.config.endpoint + apiPath);
const apiHeaders = {};
return this.client.call(
"get",
uri,
apiHeaders,
payload,
"arrayBuffer"
);
}
};
export { Storage };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=storage.mjs.map