quackscape/assets/js/api.js
Kumi 7d78c5d4a0
feat: Introduce file upload functionality
This commit overhauls the user area with the addition of comprehensive
file upload capabilities for images and videos. Notably, it integrates
front-end enhancements for drag-and-drop uploads in the user area and
introduces a secure back-end handling process. The back-end adjustments
include a new media upload view and adjustments to image and video
models to support large file handling through settings for maximum image
pixel limits. Additionally, the refactor standardizes CSRF token
retrieval across JavaScript modules, improving security and code
maintainability.

- Front-end additions include detailed user feedback during the file
upload process, such as progress bars and success/error indicators.
- Back-end improvements ensure large image files are processed
efficiently, mitigating potential memory issues by configuring a maximum
image pixel threshold.
- Consolidating the CSRF token retrieval into the `api.js` module
centralizes security mechanisms, reducing redundancy and enhancing the
codebase's clarity.

Overall, these changes enrich the platform's media management
capabilities, bolster security practices, and improve user experience
through intuitive interface updates and robust back-end processing.
2024-03-16 21:30:12 +01:00

69 lines
1.9 KiB
JavaScript

import SwaggerClient from "swagger-client";
const url = String(new URL("/api/", document.baseURI));
const api = new SwaggerClient(url);
api.then(
(client) => (window.client = client),
(reason) => console.error("Failed to load OpenAPI spec: " + reason)
);
function getScene(uuid) {
return api
.then(
(client) => client.apis.tours.tours_api_scenes_retrieve({ id: uuid }),
(reason) => console.error("Failed to load OpenAPI spec: " + reason)
)
.then(
(result) => result,
(reason) => console.error("Failed to execute API call: " + reason)
);
}
function getSceneElement(scene_uuid, uuid) {
return api
.then(
(client) =>
client.apis.tours.tours_api_scene_elements_retrieve({
scene: scene_uuid,
id: uuid,
}),
(reason) => console.error("Failed to load OpenAPI spec: " + reason)
)
.then(
(result) => result,
(reason) => console.error("Failed to execute API call: " + reason)
);
}
function getCategory(category) {
return api
.then(
(client) =>
client.apis.tours.tours_api_categories_retrieve({ id: category }),
(reason) => console.error("Failed to load OpenAPI spec: " + reason)
)
.then(
(result) => result,
(reason) => console.error("Failed to execute API call: " + reason)
);
}
// Function to get the CSRF token cookie. Not exactly "API", but fits here best.
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== "") {
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === name + "=") {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
export { getScene, getSceneElement, getCategory, getCookie };