mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Merge pull request #3809 from RaenonX/master
Allow `browser` / `os` / `device` override in `payload` & return `cache` from `/api/batch`
This commit is contained in:
commit
23ff20a10b
3 changed files with 12 additions and 4 deletions
|
|
@ -17,6 +17,7 @@ export async function POST(request: Request) {
|
|||
const errors = [];
|
||||
|
||||
let index = 0;
|
||||
let cache = null;
|
||||
for (const data of body) {
|
||||
// Recreate a fresh Request since `new Request(request)` will have the following error:
|
||||
// > Cannot read private member #state from an object whose class did not declare it
|
||||
|
|
@ -33,9 +34,12 @@ export async function POST(request: Request) {
|
|||
});
|
||||
|
||||
const response = await send.POST(newRequest);
|
||||
const responseJson = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
errors.push({ index, response: await response.json() });
|
||||
errors.push({ index, response: responseJson });
|
||||
} else {
|
||||
cache ??= responseJson.cache;
|
||||
}
|
||||
|
||||
index++;
|
||||
|
|
@ -46,6 +50,7 @@ export async function POST(request: Request) {
|
|||
processed: body.length - errors.length,
|
||||
errors: errors.length,
|
||||
details: errors,
|
||||
cache,
|
||||
});
|
||||
} catch (e) {
|
||||
return serverError(e);
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ const schema = z.object({
|
|||
userAgent: z.string().optional(),
|
||||
timestamp: z.coerce.number().int().optional(),
|
||||
id: z.string().optional(),
|
||||
browser: z.string().optional(),
|
||||
os: z.string().optional(),
|
||||
device: z.string().optional(),
|
||||
})
|
||||
.refine(
|
||||
data => {
|
||||
|
|
|
|||
|
|
@ -114,9 +114,9 @@ export async function getClientInfo(request: Request, payload: Record<string, an
|
|||
const country = safeDecodeURIComponent(location?.country);
|
||||
const region = safeDecodeURIComponent(location?.region);
|
||||
const city = safeDecodeURIComponent(location?.city);
|
||||
const browser = browserName(userAgent);
|
||||
const os = detectOS(userAgent) as string;
|
||||
const device = getDevice(userAgent, payload?.screen);
|
||||
const browser = payload?.browser ?? browserName(userAgent);
|
||||
const os = payload?.os ?? (detectOS(userAgent) as string);
|
||||
const device = payload?.device ?? getDevice(userAgent, payload?.screen);
|
||||
|
||||
return { userAgent, browser, os, ip, country, region, city, device };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue