feat: 请求增加requestid
This commit is contained in:
@ -3,6 +3,7 @@ import type { EventSourceMessage } from '@microsoft/fetch-event-source';
|
||||
import { useEnterpriseStore } from '@/stores/modules/enterprise';
|
||||
import { glsWithCatch } from '@/utils/stroage';
|
||||
import { BASE_PYTHON_URL } from '@/api/all/chat';
|
||||
import { genRandomId } from '@/utils/tools';
|
||||
|
||||
const DEFAULT_SSE_URL = `${BASE_PYTHON_URL}/api/agent/runs`;
|
||||
|
||||
@ -11,6 +12,7 @@ const SSE_HEADERS = {
|
||||
'Cache-Control': 'no-cache',
|
||||
Connection: 'keep-alive',
|
||||
Accept: 'text/event-stream',
|
||||
requestid: genRandomId(),
|
||||
};
|
||||
|
||||
interface SSEConfig {
|
||||
|
||||
@ -108,7 +108,7 @@ export function downloadByUrl(url: string, filename?: string) {
|
||||
}
|
||||
|
||||
export function genRandomId() {
|
||||
return `id_${Date.now()}_${Math.floor(Math.random() * 10000)}`;
|
||||
return `id_${dayjs().unix()}_${Math.floor(Math.random() * 10000)}`;
|
||||
}
|
||||
|
||||
export function formatFileSize(bytes: number): string {
|
||||
@ -397,7 +397,7 @@ export function getImageMainColor(imageUrl: string): Promise<string> {
|
||||
const avgColor = {
|
||||
r: Math.round(maxGroup.sumR / maxGroup.count),
|
||||
g: Math.round(maxGroup.sumG / maxGroup.count),
|
||||
b: Math.round(maxGroup.sumB / maxGroup.count)
|
||||
b: Math.round(maxGroup.sumB / maxGroup.count),
|
||||
};
|
||||
|
||||
resolve(`rgb(${avgColor.r},${avgColor.g},${avgColor.b})`);
|
||||
@ -427,28 +427,38 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
|
||||
if (a < 128) continue;
|
||||
|
||||
colors.push({
|
||||
r, g, b,
|
||||
r,
|
||||
g,
|
||||
b,
|
||||
count: 1,
|
||||
sumR: r, sumG: g, sumB: b
|
||||
sumR: r,
|
||||
sumG: g,
|
||||
sumB: b,
|
||||
});
|
||||
}
|
||||
|
||||
// 如果没有颜色数据,返回默认白色
|
||||
if (colors.length === 0) {
|
||||
return [{
|
||||
count: 1,
|
||||
sumR: 255, sumG: 255, sumB: 255
|
||||
}];
|
||||
return [
|
||||
{
|
||||
count: 1,
|
||||
sumR: 255,
|
||||
sumG: 255,
|
||||
sumB: 255,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
// 开始中位数切分
|
||||
let colorGroups = [{
|
||||
colors,
|
||||
count: colors.length,
|
||||
sumR: colors.reduce((sum, c) => sum + c.r, 0),
|
||||
sumG: colors.reduce((sum, c) => sum + c.g, 0),
|
||||
sumB: colors.reduce((sum, c) => sum + c.b, 0)
|
||||
}];
|
||||
let colorGroups = [
|
||||
{
|
||||
colors,
|
||||
count: colors.length,
|
||||
sumR: colors.reduce((sum, c) => sum + c.r, 0),
|
||||
sumG: colors.reduce((sum, c) => sum + c.g, 0),
|
||||
sumB: colors.reduce((sum, c) => sum + c.b, 0),
|
||||
},
|
||||
];
|
||||
|
||||
for (let i = 0; i < levels; i++) {
|
||||
const newGroups = [];
|
||||
@ -460,12 +470,12 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
|
||||
}
|
||||
|
||||
// 找出颜色范围最大的通道
|
||||
const rMin = Math.min(...group.colors.map(c => c.r));
|
||||
const rMax = Math.max(...group.colors.map(c => c.r));
|
||||
const gMin = Math.min(...group.colors.map(c => c.g));
|
||||
const gMax = Math.max(...group.colors.map(c => c.g));
|
||||
const bMin = Math.min(...group.colors.map(c => c.b));
|
||||
const bMax = Math.max(...group.colors.map(c => c.b));
|
||||
const rMin = Math.min(...group.colors.map((c) => c.r));
|
||||
const rMax = Math.max(...group.colors.map((c) => c.r));
|
||||
const gMin = Math.min(...group.colors.map((c) => c.g));
|
||||
const gMax = Math.max(...group.colors.map((c) => c.g));
|
||||
const bMin = Math.min(...group.colors.map((c) => c.b));
|
||||
const bMax = Math.max(...group.colors.map((c) => c.b));
|
||||
|
||||
const rRange = rMax - rMin;
|
||||
const gRange = gMax - gMin;
|
||||
@ -500,7 +510,7 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
|
||||
count: group1.length,
|
||||
sumR: group1.reduce((sum, c) => sum + c.r, 0),
|
||||
sumG: group1.reduce((sum, c) => sum + c.g, 0),
|
||||
sumB: group1.reduce((sum, c) => sum + c.b, 0)
|
||||
sumB: group1.reduce((sum, c) => sum + c.b, 0),
|
||||
});
|
||||
|
||||
newGroups.push({
|
||||
@ -508,7 +518,7 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
|
||||
count: group2.length,
|
||||
sumR: group2.reduce((sum, c) => sum + c.r, 0),
|
||||
sumG: group2.reduce((sum, c) => sum + c.g, 0),
|
||||
sumB: group2.reduce((sum, c) => sum + c.b, 0)
|
||||
sumB: group2.reduce((sum, c) => sum + c.b, 0),
|
||||
});
|
||||
}
|
||||
|
||||
@ -516,4 +526,4 @@ function medianCut(data: Uint8ClampedArray, levels: number): any[] {
|
||||
}
|
||||
|
||||
return colorGroups;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user