Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
weaigc committed Sep 9, 2023
1 parent 98e9dc7 commit 3348a51
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
38 changes: 38 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
"jotai-location": "^0.5.1",
"js-base64": "^3.7.5",
"lodash": "^4.17.21",
"md5": "^2.3.0",
"namestorage": "^1.3.0",
"nanoid": "^4.0.2",
"next": "13.4.19",
"next-auth": "^4.23.1",
"next-themes": "^0.2.1",
"node-imei": "^1.0.8",
"postcss": "8.4.29",
"random-ip": "^0.0.1",
"react": "18.2.0",
Expand Down
12 changes: 9 additions & 3 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { clsx, type ClassValue } from 'clsx'
import md5 from 'md5'
import { customAlphabet } from 'nanoid'
import { twMerge } from 'tailwind-merge'
import dayjs from 'dayjs'
import { lookup } from 'dns'
// @ts-ignore
import imei from 'node-imei'
// @ts-ignore
import randomip from 'random-ip'
import cidr from './cidr.json'
import { debug } from './isomorphic'

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
Expand Down Expand Up @@ -38,13 +40,16 @@ export function createChunkDecoder() {
}
}

export function muid() {
return md5(imei.random()).toUpperCase()
}

export function random(start: number, end: number) {
return start + Math.floor(Math.random() * (end - start))
}

export function randomString(length: number = 32) {
const char = 'ABCDEFGHJKMNPQRSTWXYZ1234567890';
let n = '';
return Array.from({ length }, () => char.charAt(random(0, char.length))).join('')
}

Expand Down Expand Up @@ -124,6 +129,7 @@ export function parseCookies(cookie: string, cookieNames: string[]) {
}

export const DEFAULT_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.0.0'
export const DEFAULT_UA_MOBILE = `Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.7 Mobile/15E148 Safari/605.1.15 BingSapphire/1.0.410427012`

export function parseUA(ua?: string, default_ua = DEFAULT_UA) {
return / EDGE?/i.test(decodeURIComponent(ua || '')) ? decodeURIComponent(ua!.trim()) : default_ua
Expand All @@ -143,7 +149,7 @@ export function mockUser(cookies: Partial<{ [key: string]: string }>) {
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'User-Agent': ua!,
'x-ms-useragent': 'azsdk-js-api-client-factory/1.0.0-beta.1 core-rest-pipeline/1.10.3 OS/Win32',
cookie: `_U=${_U}; MUID=${randomString(32)}`,
cookie: `_U=${_U}; MUID=${muid()}`,
}
}

Expand Down

0 comments on commit 3348a51

Please sign in to comment.