mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
add limit to files on publication
This commit is contained in:
@@ -4,7 +4,7 @@ import { HttpClient, HttpHeaders, HttpEventType } from '@angular/common/http';
|
||||
import { LoginUserRespose, UserForm, UserSession } from '../models/user.model';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { BehaviorSubject, of } from 'rxjs';
|
||||
import { AlertController } from '@ionic/angular';
|
||||
import { AlertController, Platform } from '@ionic/angular';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
import { AESEncrypt } from '../services/aesencrypt.service';
|
||||
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service';
|
||||
@@ -50,7 +50,8 @@ export class AuthService {
|
||||
public p: PermissionService,
|
||||
public ChatSystemService: ChatSystemService,
|
||||
private httpErroHandle: HttpErrorHandle,
|
||||
private errorHandler: ErrorHandler) {
|
||||
private errorHandler: ErrorHandler,
|
||||
private platform: Platform,) {
|
||||
|
||||
if (SessionStore.exist) {
|
||||
if (this.p.userPermission(this.p.permissionList.Chat.access) == true) {
|
||||
@@ -90,9 +91,16 @@ export class AuthService {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
}
|
||||
let channelId;
|
||||
if ( this.platform.is('desktop') || this.platform.is("mobileweb")){
|
||||
channelId = 2
|
||||
} else {
|
||||
channelId = 1
|
||||
}
|
||||
|
||||
let body = {
|
||||
"Auth": user.BasicAuthKey,
|
||||
"ChannelId": 1
|
||||
"ChannelId": channelId
|
||||
}
|
||||
|
||||
let response: any;
|
||||
|
||||
@@ -370,7 +370,7 @@ export class ChatService {
|
||||
|
||||
async refreshtoken() {
|
||||
|
||||
if(this.headers && SessionStore.user.ChatData) {
|
||||
/* if(this.headers && SessionStore.user.ChatData) {
|
||||
this.headers = this.headers.set('Authorization', 'Bearer ' + SessionStore.user.Authorization);
|
||||
let options = {
|
||||
headers: this.headers
|
||||
@@ -406,10 +406,13 @@ export class ChatService {
|
||||
})
|
||||
} else {
|
||||
|
||||
setTimeout(async () => {
|
||||
this.resetTimer();
|
||||
await this.refreshtoken();
|
||||
}, 60000)
|
||||
if(SessionStore.user.Authorization != '') {
|
||||
setTimeout(async () => {
|
||||
this.resetTimer();
|
||||
await this.refreshtoken();
|
||||
}, 60000)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -420,7 +423,7 @@ export class ChatService {
|
||||
} else if (!this.headers) {
|
||||
this.setheader()
|
||||
this.refreshtoken()
|
||||
}
|
||||
} */
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -96,6 +96,9 @@ export class HttpErrorHandle {
|
||||
case 'filetype':
|
||||
this.toastService._badRequest('Formato de ficheiro inválido!')
|
||||
break;
|
||||
case 'filessize':
|
||||
this.toastService._badRequest('Excedeu o limite de 20 MB!')
|
||||
break;
|
||||
|
||||
default:
|
||||
this.toastService._badRequest('')
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Filesystem, FilesystemDirectory } from '@capacitor/filesystem';
|
||||
import { Platform } from '@ionic/angular';
|
||||
|
||||
declare var FFmpeg: any;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class VideoCompressionService {
|
||||
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private platform: Platform
|
||||
) { }
|
||||
|
||||
async compressVideo(inputFile: string, outputFileName: string, quality: string = 'medium'): Promise<void> {
|
||||
// Load FFmpeg
|
||||
await this.loadFFmpeg();
|
||||
|
||||
// Input file
|
||||
const inputBuffer = await this.fetchVideo(inputFile);
|
||||
|
||||
// Output file path
|
||||
const outputPath = await this.getOutputFilePath(outputFileName);
|
||||
|
||||
// Run FFmpeg command
|
||||
await this.runFFmpegCommand(inputBuffer, outputPath, quality);
|
||||
|
||||
console.log('Video compression complete!');
|
||||
}
|
||||
|
||||
private async loadFFmpeg(): Promise<void> {
|
||||
if (!FFmpeg.isLoaded()) {
|
||||
await FFmpeg.load();
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchVideo(url: string): Promise<ArrayBuffer> {
|
||||
const response = await this.http.get(url, { responseType: 'arraybuffer' }).toPromise();
|
||||
return response;
|
||||
}
|
||||
|
||||
private async getOutputFilePath(outputFileName: string): Promise<string> {
|
||||
const dataDirectory = await Filesystem.getUri({
|
||||
directory: FilesystemDirectory.Data,
|
||||
path: ''
|
||||
});
|
||||
|
||||
return `${dataDirectory.uri}/${outputFileName}`;
|
||||
}
|
||||
|
||||
private async runFFmpegCommand(inputBuffer: ArrayBuffer, outputPath: string, quality: string): Promise<void> {
|
||||
await FFmpeg.run('-i', inputBuffer, '-c:v', 'libx264', '-preset', quality, outputPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Mobile
|
||||
/* import { Injectable } from '@angular/core';
|
||||
import { HTTP } from '@ionic-native/http/ngx';
|
||||
import { Filesystem, FilesystemDirectory, FilesystemEncoding } from '@capacitor/filesystem';
|
||||
import { Platform } from '@ionic/angular';
|
||||
|
||||
declare var FFmpeg: any;
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class VideoCompressionService {
|
||||
|
||||
constructor(
|
||||
private http: HTTP,
|
||||
private platform: Platform
|
||||
) { }
|
||||
|
||||
async compressVideo(inputFile: string, outputFileName: string, quality: string = 'medium'): Promise<void> {
|
||||
// Load FFmpeg
|
||||
await this.loadFFmpeg();
|
||||
|
||||
// Input file
|
||||
const inputBuffer = await this.fetchVideo(inputFile);
|
||||
|
||||
// Output file path
|
||||
const outputPath = await this.getOutputFilePath(outputFileName);
|
||||
|
||||
// Run FFmpeg command
|
||||
await this.runFFmpegCommand(inputBuffer, outputPath, quality);
|
||||
|
||||
console.log('Video compression complete!');
|
||||
}
|
||||
|
||||
private async loadFFmpeg(): Promise<void> {
|
||||
if (!FFmpeg.isLoaded()) {
|
||||
await FFmpeg.load();
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchVideo(url: string): Promise<ArrayBuffer> {
|
||||
const response = await this.http.sendRequest(url, {
|
||||
method: 'get',
|
||||
responseType: 'arraybuffer'
|
||||
});
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
private async getOutputFilePath(outputFileName: string): Promise<string> {
|
||||
const dataDirectory = await Filesystem.getUri({
|
||||
directory: FilesystemDirectory.Data,
|
||||
path: ''
|
||||
});
|
||||
|
||||
return `${dataDirectory.uri}/${outputFileName}`;
|
||||
}
|
||||
|
||||
private async runFFmpegCommand(inputBuffer: ArrayBuffer, outputPath: string, quality: string): Promise<void> {
|
||||
await FFmpeg.run('-i', inputBuffer, '-c:v', 'libx264', '-preset', quality, outputPath);
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user