mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-16 10:01:29 +03:00
Fixed bug that caused users with large amounts of data to have extremely large tokens
Subfolders are now ensured to exist with the normal downloading method Initialization now happens after token retrieval to avoid failed requests Fixed bug that caused login to be called twice, introducing a possible race condition
This commit is contained in:
@@ -1365,7 +1365,9 @@ async function downloadFileByURL_normal(url, type, options, sessionID = null) {
|
|||||||
video.on('info', function(info) {
|
video.on('info', function(info) {
|
||||||
video_info = info;
|
video_info = info;
|
||||||
file_size = video_info.size;
|
file_size = video_info.size;
|
||||||
fs.writeJSONSync(removeFileExtension(video_info._filename) + '.info.json', video_info);
|
const json_path = removeFileExtension(video_info._filename) + '.info.json';
|
||||||
|
fs.ensureFileSync(json_path);
|
||||||
|
fs.writeJSONSync(json_path, video_info);
|
||||||
video.pipe(fs.createWriteStream(video_info._filename, { flags: 'w' }))
|
video.pipe(fs.createWriteStream(video_info._filename, { flags: 'w' }))
|
||||||
});
|
});
|
||||||
// Will be called if download was already completed and there is nothing more to download.
|
// Will be called if download was already completed and there is nothing more to download.
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ exports.initialize = function(input_users_db, input_logger) {
|
|||||||
opts.audience = 'example.com';*/
|
opts.audience = 'example.com';*/
|
||||||
|
|
||||||
exports.passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
|
exports.passport.use(new JwtStrategy(opts, function(jwt_payload, done) {
|
||||||
const user = users_db.get('users').find({uid: jwt_payload.user.uid}).value();
|
const user = users_db.get('users').find({uid: jwt_payload.user}).value();
|
||||||
if (user) {
|
if (user) {
|
||||||
return done(null, user);
|
return done(null, user);
|
||||||
} else {
|
} else {
|
||||||
@@ -209,7 +209,7 @@ exports.authenticateViaPassport = function(req, res, next) {
|
|||||||
exports.generateJWT = function(req, res, next) {
|
exports.generateJWT = function(req, res, next) {
|
||||||
var payload = {
|
var payload = {
|
||||||
exp: Math.floor(Date.now() / 1000) + JWT_EXPIRATION
|
exp: Math.floor(Date.now() / 1000) + JWT_EXPIRATION
|
||||||
, user: req.user
|
, user: req.user.uid
|
||||||
};
|
};
|
||||||
req.token = jwt.sign(payload, SERVER_SECRET);
|
req.token = jwt.sign(payload, SERVER_SECRET);
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -41,12 +41,15 @@ export class LoginComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
if (this.loginPasswordInput === '') {
|
if (this.loginPasswordInput === '' || this.loggingIn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.loggingIn = true;
|
this.loggingIn = true;
|
||||||
this.postsService.login(this.loginUsernameInput, this.loginPasswordInput).subscribe(res => {
|
this.postsService.login(this.loginUsernameInput, this.loginPasswordInput).subscribe(res => {
|
||||||
this.loggingIn = false;
|
this.loggingIn = false;
|
||||||
|
if (res['token']) {
|
||||||
|
this.postsService.afterLogin(res['user'], res['token'], res['permissions'], res['available_permissions']);
|
||||||
|
}
|
||||||
}, err => {
|
}, err => {
|
||||||
this.loggingIn = false;
|
this.loggingIn = false;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Injectable, isDevMode, Inject} from '@angular/core';
|
import {Injectable, isDevMode, Inject} from '@angular/core';
|
||||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
import 'rxjs/add/operator/catch';
|
import 'rxjs/add/operator/catch';
|
||||||
@@ -64,7 +64,7 @@ export class PostsService implements CanActivate {
|
|||||||
this.httpOptions = {
|
this.httpOptions = {
|
||||||
params: new HttpParams({
|
params: new HttpParams({
|
||||||
fromString: this.http_params
|
fromString: this.http_params
|
||||||
}),
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
Fingerprint2.get(components => {
|
Fingerprint2.get(components => {
|
||||||
@@ -83,7 +83,6 @@ export class PostsService implements CanActivate {
|
|||||||
if (localStorage.getItem('jwt_token')) {
|
if (localStorage.getItem('jwt_token')) {
|
||||||
this.token = localStorage.getItem('jwt_token');
|
this.token = localStorage.getItem('jwt_token');
|
||||||
this.httpOptions.params = this.httpOptions.params.set('jwt', this.token);
|
this.httpOptions.params = this.httpOptions.params.set('jwt', this.token);
|
||||||
|
|
||||||
this.jwtAuth();
|
this.jwtAuth();
|
||||||
} else {
|
} else {
|
||||||
this.sendToLogin();
|
this.sendToLogin();
|
||||||
@@ -335,12 +334,13 @@ export class PostsService implements CanActivate {
|
|||||||
this.permissions = permissions;
|
this.permissions = permissions;
|
||||||
this.available_permissions = available_permissions;
|
this.available_permissions = available_permissions;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.setInitialized();
|
|
||||||
|
|
||||||
localStorage.setItem('jwt_token', this.token);
|
localStorage.setItem('jwt_token', this.token);
|
||||||
|
|
||||||
this.httpOptions.params = this.httpOptions.params.set('jwt', this.token);
|
this.httpOptions.params = this.httpOptions.params.set('jwt', this.token);
|
||||||
|
console.log(this.httpOptions);
|
||||||
|
|
||||||
|
this.setInitialized();
|
||||||
// needed to re-initialize parts of app after login
|
// needed to re-initialize parts of app after login
|
||||||
this.config_reloaded.next(true);
|
this.config_reloaded.next(true);
|
||||||
|
|
||||||
@@ -352,25 +352,23 @@ export class PostsService implements CanActivate {
|
|||||||
// user methods
|
// user methods
|
||||||
login(username, password) {
|
login(username, password) {
|
||||||
const call = this.http.post(this.path + 'auth/login', {userid: username, password: password}, this.httpOptions);
|
const call = this.http.post(this.path + 'auth/login', {userid: username, password: password}, this.httpOptions);
|
||||||
call.subscribe(res => {
|
|
||||||
if (res['token']) {
|
|
||||||
this.afterLogin(res['user'], res['token'], res['permissions'], res['available_permissions']);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return call;
|
return call;
|
||||||
}
|
}
|
||||||
|
|
||||||
// user methods
|
// user methods
|
||||||
jwtAuth() {
|
jwtAuth() {
|
||||||
|
console.log('doing jwt call');
|
||||||
const call = this.http.post(this.path + 'auth/jwtAuth', {}, this.httpOptions);
|
const call = this.http.post(this.path + 'auth/jwtAuth', {}, this.httpOptions);
|
||||||
call.subscribe(res => {
|
call.subscribe(res => {
|
||||||
if (res['token']) {
|
if (res['token']) {
|
||||||
this.afterLogin(res['user'], res['token'], res['permissions'], res['available_permissions']);
|
this.afterLogin(res['user'], res['token'], res['permissions'], res['available_permissions']);
|
||||||
}
|
}
|
||||||
}, err => {
|
}, err => {
|
||||||
|
console.log('jwt errored')
|
||||||
if (err.status === 401) {
|
if (err.status === 401) {
|
||||||
this.sendToLogin();
|
this.sendToLogin();
|
||||||
}
|
}
|
||||||
|
console.log(err)
|
||||||
});
|
});
|
||||||
return call;
|
return call;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user