wip: shopping cart
This commit is contained in:
@@ -1,11 +1,26 @@
|
||||
import {$fetch} from "ofetch";
|
||||
import {ofetch} from "ofetch";
|
||||
|
||||
const BASE_URL = '/';
|
||||
|
||||
export const apiFetch = ofetch.create({
|
||||
onRequest({ request, options }) {
|
||||
const initData = window.Telegram?.WebApp?.initData
|
||||
|
||||
if (initData) {
|
||||
options.headers = {
|
||||
...options.headers,
|
||||
'X-Telegram-InitData': initData,
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default async function (action, query = null, json = null) {
|
||||
return await $fetch(`${BASE_URL}index.php?route=extension/tgshop/handle&api_action=${action}`, {
|
||||
const options = {
|
||||
method: json ? 'POST' : 'GET',
|
||||
query: query,
|
||||
body: json,
|
||||
});
|
||||
}
|
||||
if (query) options.query = query;
|
||||
if (json) options.body = json;
|
||||
|
||||
return await apiFetch(`${BASE_URL}index.php?route=extension/tgshop/handle&api_action=${action}`, options);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user