fix(miniapp): inline createUuid in config to fix DevTools require
WeChat DevTools failed to resolve utils/uuid.js at runtime; move UUID generation into config.js which is already loaded by app.js. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
const SESSION_KEY = 'tkmind_session';
|
const SESSION_KEY = 'tkmind_session';
|
||||||
const { createUuid } = require('./uuid');
|
const { createUuid } = require('./config');
|
||||||
|
|
||||||
let apiBaseUrl = '';
|
let apiBaseUrl = '';
|
||||||
let cookie = '';
|
let cookie = '';
|
||||||
|
|||||||
@@ -2,6 +2,17 @@
|
|||||||
// Local Portal debug: set LOCAL_DEV = true, or copy config.local.example.js → config.local.js
|
// Local Portal debug: set LOCAL_DEV = true, or copy config.local.example.js → config.local.js
|
||||||
const LOCAL_DEV = false;
|
const LOCAL_DEV = false;
|
||||||
|
|
||||||
|
function createUuid() {
|
||||||
|
const bytes = [];
|
||||||
|
for (let i = 0; i < 16; i += 1) {
|
||||||
|
bytes.push(Math.floor(Math.random() * 256));
|
||||||
|
}
|
||||||
|
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
||||||
|
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
||||||
|
const hex = bytes.map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
||||||
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
||||||
|
}
|
||||||
|
|
||||||
const defaults = {
|
const defaults = {
|
||||||
API_BASE_URL: LOCAL_DEV ? 'http://127.0.0.1:8081' : 'https://m.tkmind.cn',
|
API_BASE_URL: LOCAL_DEV ? 'http://127.0.0.1:8081' : 'https://m.tkmind.cn',
|
||||||
MINIAPP_LOGIN_PATH: '/auth/wechat-miniapp/login',
|
MINIAPP_LOGIN_PATH: '/auth/wechat-miniapp/login',
|
||||||
@@ -18,6 +29,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
createUuid,
|
||||||
...defaults,
|
...defaults,
|
||||||
...localOverrides,
|
...localOverrides,
|
||||||
...(localOverrides.API_BASE_URL
|
...(localOverrides.API_BASE_URL
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const { createUuid } = require('./uuid');
|
const { createUuid } = require('./config');
|
||||||
const { buildMessageView } = require('./message-display');
|
const { buildMessageView } = require('./message-display');
|
||||||
|
|
||||||
function createUserMessage(text) {
|
function createUserMessage(text) {
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
function createUuid() {
|
|
||||||
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
||||||
return crypto.randomUUID();
|
|
||||||
}
|
|
||||||
const bytes = new Uint8Array(16);
|
|
||||||
if (typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function') {
|
|
||||||
crypto.getRandomValues(bytes);
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < 16; i += 1) {
|
|
||||||
bytes[i] = Math.floor(Math.random() * 256);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
||||||
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
||||||
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
||||||
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
createUuid,
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user