mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-08 17:06:15 -08:00
refactor: code improvements
This commit is contained in:
1 parent
3cb33aa9d0
commit
994b1cf9f5
7 files changed
+37
-56
No files matched your search
@@ -3,9 +3,9 @@ import { parse } from 'iptv-playlist-parser';
|
||||
import axios from 'axios';
|
||||
import { guid } from '@datorama/akita';
|
||||
import { Playlist } from './src/app/playlist-uploader/playlist.interface';
|
||||
import Nedb from 'nedb-promises-ts';
|
||||
|
||||
const Datastore = require('nedb');
|
||||
const db = new Datastore({ filename: 'data.db', autoload: true });
|
||||
const db = new Nedb<Playlist>({ filename: 'data.db', autoload: true });
|
||||
|
||||
export class Api {
|
||||
constructor() {
|
||||
@@ -34,31 +34,27 @@ export class Api {
|
||||
event.sender.send('parse-response', { payload: playlistObject });
|
||||
});
|
||||
|
||||
ipcMain.on('playlists-all', (event, args) => {
|
||||
db.find({}, { count: 1, title: 1, _id: 1 }, function (
|
||||
err,
|
||||
playlists
|
||||
) {
|
||||
event.sender.send('playlist-all-result', {
|
||||
payload: playlists,
|
||||
});
|
||||
ipcMain.on('playlists-all', async (event, args) => {
|
||||
const playlists = await db.find({}, { count: 1, title: 1, _id: 1 });
|
||||
event.sender.send('playlist-all-result', {
|
||||
payload: playlists,
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('playlist-by-id', (event, args) => {
|
||||
db.findOne({ _id: args.id }, function (err, playlist) {
|
||||
event.sender.send('playlist-by-id-result', {
|
||||
payload: playlist,
|
||||
});
|
||||
ipcMain.on('playlist-by-id', async (event, args) => {
|
||||
const playlist = await db.findOne({ _id: args.id });
|
||||
event.sender.send('playlist-by-id-result', {
|
||||
payload: playlist,
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.on('playlist-remove-by-id', (event, args) => {
|
||||
db.remove({ _id: args.id }, function (err, playlist) {
|
||||
ipcMain.on('playlist-remove-by-id', async (event, args) => {
|
||||
const removed = await db.remove({ _id: args.id });
|
||||
if (removed) {
|
||||
event.sender.send('playlist-remove-by-id-result', {
|
||||
message: 'playlist was removed',
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -95,8 +91,8 @@ export class Api {
|
||||
* @param playlist playlist to add
|
||||
*/
|
||||
insertToDb(playlist) {
|
||||
db.insert(playlist, function (err, newrec) {
|
||||
console.log('playlist was saved...', newrec._id);
|
||||
db.insert(playlist).then((response) => {
|
||||
console.log('playlist was saved...', response._id);
|
||||
});
|
||||
}
|
||||
}
|
||||
Generated
+8
-28
@@ -7755,29 +7755,6 @@
|
||||
"extract-zip": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"electron-better-ipc": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/electron-better-ipc/-/electron-better-ipc-1.1.1.tgz",
|
||||
"integrity": "sha512-Y8Ty54HJtzT6aWNTyE092W/7q8y3+yJz0XvRpOKGIsLDL2H7oWIFkUegmB+6h5SszjtBiQFpmNmHOKfkDZ8HbQ==",
|
||||
"requires": {
|
||||
"serialize-error": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"serialize-error": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-5.0.0.tgz",
|
||||
"integrity": "sha512-/VtpuyzYf82mHYTtI4QKtwHa79vAdU5OQpNPAmE/0UDdlGT0ZxHwC+J6gXkw29wwoVI8fMPsfcVHOwXtUQYYQA==",
|
||||
"requires": {
|
||||
"type-fest": "^0.8.0"
|
||||
}
|
||||
},
|
||||
"type-fest": {
|
||||
"version": "0.8.1",
|
||||
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz",
|
||||
"integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"electron-builder": {
|
||||
"version": "22.7.0",
|
||||
"resolved": "https://registry.npmjs.org/electron-builder/-/electron-builder-22.7.0.tgz",
|
||||
@@ -13398,6 +13375,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"nedb-promises-ts": {
|
||||
"version": "0.0.1-4",
|
||||
"resolved": "https://registry.npmjs.org/nedb-promises-ts/-/nedb-promises-ts-0.0.1-4.tgz",
|
||||
"integrity": "sha512-vEYqn9pyf7RrLiC9yfnCq/kn3I/bPH0bRwDK8tF3HqcqX9I0wrbMI12pxZbz79QZdlyOVjeYvu7JY9yl4sL0yw==",
|
||||
"requires": {
|
||||
"nedb": "^1.8.0"
|
||||
}
|
||||
},
|
||||
"negotiator": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
||||
@@ -13431,11 +13416,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"ngx-indexed-db": {
|
||||
"version": "5.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ngx-indexed-db/-/ngx-indexed-db-5.0.5.tgz",
|
||||
"integrity": "sha512-MRqtL51HoZp9CUEaQQEQY4pjuwDJmG5/ucHfxy8LaPEyW+HOL+kvAgXKumDiUH5Q/K0WNQwoQwSxPUFnsUQrdQ=="
|
||||
},
|
||||
"ngx-uploader": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ngx-uploader/-/ngx-uploader-10.0.0.tgz",
|
||||
|
||||
+2
-2
@@ -104,14 +104,14 @@
|
||||
"@types/hls.js": "0.13.0",
|
||||
"axios": "0.19.2",
|
||||
"custom-electron-titlebar": "3.2.3",
|
||||
"electron-better-ipc": "1.1.1",
|
||||
"hls.js": "0.14.8",
|
||||
"iptv-playlist-parser": "0.5.0",
|
||||
"lodash": "4.17.19",
|
||||
"material-icons": "0.3.1",
|
||||
"nedb": "1.8.0",
|
||||
"nedb-promises-ts": "0.0.1-4",
|
||||
"ngx-filter-pipe": "2.1.2",
|
||||
"ngx-uploader": "10.0.0",
|
||||
"uuid": "8.3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,9 @@
|
||||
|
||||
|
||||
::ng-deep {
|
||||
.mat-tab-group {
|
||||
height: 100%;
|
||||
}
|
||||
.mat-tab-label {
|
||||
height: 63px !important;
|
||||
}
|
||||
|
||||
@@ -30,14 +30,14 @@
|
||||
<mat-form-field class="full-width">
|
||||
<input matInput placeholder="Playlist URL (m3u, m3u8)" [(ngModel)]="playlistUrl">
|
||||
</mat-form-field>
|
||||
<button mat-flat-button [disabled]="!playlistUrl" color="primary" (click)="sendUrl()">ADD PLAYLIST</button>
|
||||
<button mat-flat-button [disabled]="!playlistUrl" color="primary" (click)="sendPlaylistsUrl()">ADD PLAYLIST</button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
</div>
|
||||
<div fxFlex="50" id="recent-playlists">
|
||||
<mat-card-subtitle>Recently added playlists ({{playlists.length}})</mat-card-subtitle>
|
||||
<mat-card-subtitle>Added playlists ({{playlists.length}})</mat-card-subtitle>
|
||||
<app-recent-playlists [playlists]="playlists" (playlistClicked)="getPlaylist($event)"
|
||||
(removeClicked)="removePlaylist($event)">
|
||||
</app-recent-playlists>
|
||||
|
||||
@@ -34,13 +34,12 @@ export class PlaylistUploaderComponent {
|
||||
concurrency: 1,
|
||||
maxUploads: 1,
|
||||
};
|
||||
playlists: Playlist[] = [];
|
||||
playlists: { count: number; title: string; _id: string }[] = [];
|
||||
isLoading = false;
|
||||
|
||||
/**
|
||||
* Creates an instanceof PlaylistUploaderComponent
|
||||
* @param channelStore channels store
|
||||
* @param m3uService m3u service
|
||||
* @param router angulars router
|
||||
* @param snackBar snackbars with notification messages
|
||||
*/
|
||||
@@ -155,7 +154,10 @@ export class PlaylistUploaderComponent {
|
||||
this.router.navigateByUrl('/iptv', { skipLocationChange: true });
|
||||
}
|
||||
|
||||
sendUrl(): void {
|
||||
/**
|
||||
* Sends url of the playlist to the renderer process
|
||||
*/
|
||||
sendPlaylistsUrl(): void {
|
||||
this.renderer.send('parse-playlist-by-url', {
|
||||
title: this.getLastUrlSegment(this.playlistUrl),
|
||||
url: this.playlistUrl,
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ $material-icons-font-path: '~material-icons/iconfont/';
|
||||
|
||||
body,
|
||||
html {
|
||||
background: #56598e;
|
||||
background: #011627;
|
||||
font-family: caption;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user