mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-03-18 10:40:57 +03:00
Implemented cookies upload dialog and the ability to "enable cookies" to hopefully circumvent 429 errors
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<h4 mat-dialog-title i18n="Cookies uploader dialog title">Upload new cookies</h4>
|
||||
|
||||
<mat-dialog-content>
|
||||
<div>
|
||||
<div class="center">
|
||||
<ngx-file-drop [multiple]="false" accept=".txt" dropZoneLabel="Drop files here" (onFileDrop)="dropped($event)"
|
||||
(onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)">
|
||||
<ng-template ngx-file-drop-content-tmp let-openFileSelector="openFileSelector">
|
||||
<div>
|
||||
<div>
|
||||
<ng-container i18n="Drag and Drop">Drag and Drop</ng-container>
|
||||
</div>
|
||||
<div style="margin-top: 6px;">
|
||||
<button mat-stroked-button (click)="openFileSelector()">Browse Files</button>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
</ngx-file-drop>
|
||||
<div style="margin-top: 15px;">
|
||||
<p style="font-size: 14px;" i18n="Cookies upload warning">NOTE: Uploading new cookies will overrride your previous cookies. Also note that cookies are instance-wide, not per-user.</p>
|
||||
</div>
|
||||
<div style="margin-top: 10px;">
|
||||
<table class="table">
|
||||
<tbody class="upload-name-style">
|
||||
<tr *ngFor="let item of files; let i=index">
|
||||
<td style="vertical-align: middle;">
|
||||
<strong>{{ item.relativePath }}</strong>
|
||||
</td>
|
||||
<td>
|
||||
<button [disabled]="uploading || uploaded" (click)="uploadFile()" style="float: right" matTooltip="Upload" mat-mini-fab><mat-icon>publish</mat-icon><mat-spinner *ngIf="uploading" class="spinner" [diameter]="38"></mat-spinner></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</mat-dialog-content>
|
||||
|
||||
<mat-dialog-actions><button style="margin-bottom: 5px;" mat-dialog-close mat-stroked-button><ng-container i18n="Close">Close</ng-container></button></mat-dialog-actions>
|
||||
@@ -0,0 +1,5 @@
|
||||
.spinner {
|
||||
bottom: 1px;
|
||||
left: 0.5px;
|
||||
position: absolute;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CookiesUploaderDialogComponent } from './cookies-uploader-dialog.component';
|
||||
|
||||
describe('CookiesUploaderDialogComponent', () => {
|
||||
let component: CookiesUploaderDialogComponent;
|
||||
let fixture: ComponentFixture<CookiesUploaderDialogComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CookiesUploaderDialogComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CookiesUploaderDialogComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,57 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { NgxFileDropEntry, FileSystemFileEntry, FileSystemDirectoryEntry } from 'ngx-file-drop';
|
||||
import { PostsService } from 'app/posts.services';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cookies-uploader-dialog',
|
||||
templateUrl: './cookies-uploader-dialog.component.html',
|
||||
styleUrls: ['./cookies-uploader-dialog.component.scss']
|
||||
})
|
||||
export class CookiesUploaderDialogComponent implements OnInit {
|
||||
public files: NgxFileDropEntry[] = [];
|
||||
|
||||
uploading = false;
|
||||
uploaded = false;
|
||||
|
||||
constructor(private postsService: PostsService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
}
|
||||
|
||||
public dropped(files: NgxFileDropEntry[]) {
|
||||
this.files = files;
|
||||
this.uploading = false;
|
||||
this.uploaded = false;
|
||||
}
|
||||
|
||||
uploadFile() {
|
||||
this.uploading = true;
|
||||
for (const droppedFile of this.files) {
|
||||
// Is it a file?
|
||||
if (droppedFile.fileEntry.isFile) {
|
||||
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
|
||||
fileEntry.file((file: File) => {
|
||||
// You could upload it like this:
|
||||
const formData = new FormData()
|
||||
formData.append('cookies', file, droppedFile.relativePath);
|
||||
this.postsService.uploadCookiesFile(formData).subscribe(res => {
|
||||
this.uploading = false;
|
||||
if (res['success']) {
|
||||
this.uploaded = true;
|
||||
this.postsService.openSnackBar('Cookies successfully uploaded!');
|
||||
}
|
||||
}, err => {
|
||||
this.uploading = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public fileOver(event) {
|
||||
}
|
||||
|
||||
public fileLeave(event) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user