From 45dd7794dfcd5f6166ee4de995998463e3fa4c9b Mon Sep 17 00:00:00 2001 From: yuvraj Date: Tue, 13 Dec 2022 12:37:48 +0400 Subject: [PATCH] fix login bug + fs import --- src/handlers/common/upload_photo.ts | 2 +- src/handlers/common/upload_video.ts | 2 +- src/handlers/common/upload_video_thumbnail.ts | 2 +- src/handlers/common/validators.ts | 2 +- src/handlers/login.ts | 8 ++++---- src/http.ts | 2 +- src/shared.ts | 2 +- yarn.lock | 11 ++++------- 8 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/handlers/common/upload_photo.ts b/src/handlers/common/upload_photo.ts index 4025a7e..6c65c6e 100644 --- a/src/handlers/common/upload_photo.ts +++ b/src/handlers/common/upload_photo.ts @@ -1,6 +1,6 @@ import { BASE_URL } from '../../config'; import HTTP_CLIENT from '../../http'; -import fs from 'fs'; +import * as fs from 'fs'; import { Image, MediaUploadRes } from '../../types'; const sizeOf = require('image-size'); diff --git a/src/handlers/common/upload_video.ts b/src/handlers/common/upload_video.ts index 1499c00..6a2813c 100644 --- a/src/handlers/common/upload_video.ts +++ b/src/handlers/common/upload_video.ts @@ -1,6 +1,6 @@ import { BASE_URL } from '../../config'; import HTTP_CLIENT from '../../http'; -import fs from 'fs'; +import * as fs from 'fs'; import { MediaUploadRes } from '../../types'; async function uploadVideo({ diff --git a/src/handlers/common/upload_video_thumbnail.ts b/src/handlers/common/upload_video_thumbnail.ts index cf6bbe1..b334c15 100644 --- a/src/handlers/common/upload_video_thumbnail.ts +++ b/src/handlers/common/upload_video_thumbnail.ts @@ -1,6 +1,6 @@ import { BASE_URL } from '../../config'; import HTTP_CLIENT from '../../http'; -import fs from 'fs'; +import * as fs from 'fs'; import { MediaUploadRes } from '../../types'; const request = require('request-promise-native'); diff --git a/src/handlers/common/validators.ts b/src/handlers/common/validators.ts index 3159b80..53b55f1 100644 --- a/src/handlers/common/validators.ts +++ b/src/handlers/common/validators.ts @@ -10,7 +10,7 @@ import { VIDEO_NOT_FOUND_ERR, } from '../../errors'; import { Image } from '../../types'; -import fs from 'fs'; +import * as fs from 'fs'; const sizeOf = require('image-size'); export function validateCaption(caption: string) { diff --git a/src/handlers/login.ts b/src/handlers/login.ts index 2cf6e4a..b304983 100644 --- a/src/handlers/login.ts +++ b/src/handlers/login.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import * as fs from 'fs'; import { LOGIN_ERR, LOGIN_ERR_COOKIES } from '../errors'; import HTTP_CLIENT from '../http'; import { COOKIES_FILE_PATH } from '../config'; @@ -18,9 +18,9 @@ async function login({ let value; await HTTP_CLIENT.request('/', { resolveWithFullResponse: true }).then( res => { - const pattern = new RegExp(/(csrf_token":")\w+/); - const matches = res.toJSON().body.match(pattern); - value = matches[0].substring(13); + const pattern = new RegExp(/(csrf_token\\":\\")[\w]+/); + const matches = res.body.match(pattern); + value = matches[0].substring(15); } ); diff --git a/src/http.ts b/src/http.ts index b40f6c9..44e6e78 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,5 +1,5 @@ import { OptionsWithUri, RequestPromiseAPI } from 'request-promise-native'; -import fs from 'fs'; +import * as fs from 'fs'; import { ICookie } from './types'; import { validateCookies } from './shared'; import { BASE_URL, COOKIES_FILE_PATH } from './config'; diff --git a/src/shared.ts b/src/shared.ts index b595f64..08fdd92 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import * as fs from 'fs'; import { COOKIES_FILE_PATH } from './config'; export function validateCookies(): Boolean { diff --git a/yarn.lock b/yarn.lock index a77f1a7..7503d75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6702,13 +6702,10 @@ "resolved" "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz" "version" "3.9.10" -"typescript@^4.6.4": - "integrity" "sha512-WOkT3XYvrpXx4vMMqlD+8R8R37fZkjyLGlxavMc4iB8lrl8L0DeTcHbYgw/v0N/z9wAFsgBhcsF0ruoySS22mA==" - "resolved" "https://registry.npmjs.org/typescript/-/typescript-4.7.3.tgz" - "version" "4.7.3" - -"typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta": - "version" "3.9.10" +"typescript@^4.6.4", "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta": + "integrity" "sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==" + "resolved" "https://registry.npmjs.org/typescript/-/typescript-4.9.4.tgz" + "version" "4.9.4" "unbox-primitive@^1.0.2": "integrity" "sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw=="