Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Latest commit

 

History

History
50 lines (37 loc) · 896 Bytes

API.md

File metadata and controls

50 lines (37 loc) · 896 Bytes

API Functions

The current API is described in details here

Module

api.js »

/**
 * @description This module communicates with Lychee's API
 */

api = {
	onError: null,
};

api.post = function (fn, params, callback) {
	loadingBar.show();

	params = $.extend({ function: fn }, params);

	let api_url = "api/" + fn;

	const success = (data) => {
		setTimeout(loadingBar.hide, 100);

		// Catch errors
		if (typeof data === "string" && data.substring(0, 7) === "Error: ") {
			api.onError(data.substring(7, data.length), params, data);
			return false;
		}

		callback(data);
	};

	const error = (jqXHR, textStatus, errorThrown) => {
		api.onError("Server error or API not found.", params, errorThrown);
	};

	$.ajax({
		type: "POST",
		url: api_url,
		data: params,
		dataType: "json",
		success,
		error,
	});
};