generics: update the fetch function to work, keep old for backwards comp
This commit is contained in:
+22
-6
@@ -245,15 +245,31 @@ export const bindWaitForConnectionUpdate = (ev: BaileysEventEmitter) => bindWait
|
||||
* Use to ensure your WA connection is always on the latest version
|
||||
*/
|
||||
export const fetchLatestBaileysVersion = async (options: AxiosRequestConfig<{}> = {}) => {
|
||||
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/baileys-version.json'
|
||||
const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts'
|
||||
try {
|
||||
const result = await axios.get<{ version: WAVersion }>(URL, {
|
||||
const result = await axios.get<string>(URL, {
|
||||
...options,
|
||||
responseType: 'json'
|
||||
responseType: 'text'
|
||||
})
|
||||
return {
|
||||
version: result.data.version,
|
||||
isLatest: true
|
||||
|
||||
// Extract version from line 7 (const version = [...])
|
||||
const lines = result.data.split('\n')
|
||||
const versionLine = lines[6] // Line 7 (0-indexed)
|
||||
const versionMatch = versionLine!.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/)
|
||||
|
||||
if (versionMatch) {
|
||||
const version = [
|
||||
parseInt(versionMatch[1]!),
|
||||
parseInt(versionMatch[2]!),
|
||||
parseInt(versionMatch[3]!)
|
||||
] as WAVersion
|
||||
|
||||
return {
|
||||
version,
|
||||
isLatest: true
|
||||
}
|
||||
} else {
|
||||
throw new Error('Could not parse version from Defaults/index.ts')
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user