modified: fxmanifest.lua
deleted: main.obf.lua new file: server/utils.lua modified: web/public/assets/bg.png modified: web/src/types/redux.type.ts modified: web/src/utils/fetchNui.ts modified: web/src/utils/misc.ts
This commit is contained in:
parent
3a27609e37
commit
2b8448e1be
|
@ -34,10 +34,12 @@ shared_scripts {
|
||||||
|
|
||||||
|
|
||||||
client_scripts {
|
client_scripts {
|
||||||
|
"client/utils.lua",
|
||||||
"client/classes/*",
|
"client/classes/*",
|
||||||
"client/impl/*"
|
"client/impl/*"
|
||||||
}
|
}
|
||||||
server_script {
|
server_script {
|
||||||
|
"server/utils.lua",
|
||||||
'@oxmysql/lib/MySQL.lua',
|
'@oxmysql/lib/MySQL.lua',
|
||||||
"server/classes/*",
|
"server/classes/*",
|
||||||
"server/impl/*"
|
"server/impl/*"
|
||||||
|
|
File diff suppressed because one or more lines are too long
12
server/utils.lua
Normal file
12
server/utils.lua
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
function Response(isSuccess, errorMessage, data)
|
||||||
|
if not isSuccess then
|
||||||
|
return {
|
||||||
|
status = "error",
|
||||||
|
data = errorMessage
|
||||||
|
}
|
||||||
|
end
|
||||||
|
return {
|
||||||
|
status = "ok",
|
||||||
|
data = data
|
||||||
|
}
|
||||||
|
end
|
Binary file not shown.
Before Width: | Height: | Size: 15 MiB After Width: | Height: | Size: 4.5 MiB |
|
@ -17,3 +17,15 @@ export type AsyncThunkConfig = {
|
||||||
/** type to be passed into the second argument of `rejectWithValue` to finally be merged into `rejectedAction.meta` */
|
/** type to be passed into the second argument of `rejectWithValue` to finally be merged into `rejectedAction.meta` */
|
||||||
rejectedMeta?: unknown;
|
rejectedMeta?: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type IResponseSuccess<T = unknown> = {
|
||||||
|
status: 'success';
|
||||||
|
data: T;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type IResponseError = {
|
||||||
|
status: 'error';
|
||||||
|
data: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type IResponse<T = unknown> = IResponseSuccess<T> | IResponseError;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { isEnvBrowser } from "./misc";
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import { isEnvBrowser } from './misc';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple wrapper around fetch API tailored for CEF/NUI use. This abstraction
|
* Simple wrapper around fetch API tailored for CEF/NUI use. This abstraction
|
||||||
|
@ -15,12 +16,12 @@ import { isEnvBrowser } from "./misc";
|
||||||
export async function fetchNui<T = unknown>(
|
export async function fetchNui<T = unknown>(
|
||||||
eventName: string,
|
eventName: string,
|
||||||
data?: unknown,
|
data?: unknown,
|
||||||
mockData?: T,
|
mockData?: T
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const options = {
|
const options = {
|
||||||
method: "post",
|
method: 'post',
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json; charset=UTF-8",
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
};
|
};
|
||||||
|
@ -29,7 +30,7 @@ export async function fetchNui<T = unknown>(
|
||||||
|
|
||||||
const resourceName = (window as any).GetParentResourceName
|
const resourceName = (window as any).GetParentResourceName
|
||||||
? (window as any).GetParentResourceName()
|
? (window as any).GetParentResourceName()
|
||||||
: "nui-frame-app";
|
: 'nui-frame-app';
|
||||||
|
|
||||||
const resp = await fetch(`https://${resourceName}/${eventName}`, options);
|
const resp = await fetch(`https://${resourceName}/${eventName}`, options);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,22 @@
|
||||||
// Will return whether the current environment is in a regular browser
|
// Will return whether the current environment is in a regular browser
|
||||||
|
|
||||||
|
import { IResponse, IResponseSuccess } from '../types';
|
||||||
|
|
||||||
// and not CEF
|
// and not CEF
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
export const isEnvBrowser = (): boolean => !(window as any).invokeNative;
|
export const isEnvBrowser = (): boolean => !(window as any).invokeNative;
|
||||||
|
|
||||||
// Basic no operation function
|
// Basic no operation function
|
||||||
export const noop = () => {};
|
export const noop = () => {};
|
||||||
|
|
||||||
|
export const Sleep = (ms: number) => {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
};
|
||||||
|
|
||||||
|
export const GuardResponse = (
|
||||||
|
response: IResponse
|
||||||
|
): response is IResponseSuccess => {
|
||||||
|
if (!response) return false;
|
||||||
|
if (response.status === 'error') throw new Error(response.data);
|
||||||
|
return response.status === 'success';
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user