CacheDir & ConfigDir changed, tweaked basic configurations

This commit is contained in:
krtirtho 2021-03-06 22:40:13 +06:00
parent 247f1b563b
commit 9751b4f837
7 changed files with 28 additions and 18 deletions

View File

@ -1,8 +0,0 @@
[Desktop Entry]
Type=Application
Name=Application
Exec=AppRun %F
Icon=default
Comment=Edit this default file
Terminal=true
Categories=Utility;

View File

@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Name=Spotube
Exec=AppRun
Icon=default
Comment=A music streaming app combining the power of Spotify & Youtube
Terminal=true
Categories=Music;

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@ -13,6 +13,9 @@ import express from "express";
import open from "open";
import spotifyApi from "./initializations/spotifyApi";
import showError from "./helpers/showError";
import fs from "fs"
import path from "path";
import { confDir } from "./conf";
export enum CredentialKeys {
credentials = "credentials",
@ -26,7 +29,9 @@ export interface Credentials {
const minSize = { width: 700, height: 750 };
const winIcon = new QIcon(nodeguiIcon);
global.localStorage = new LocalStorage("./local");
const localStorageDir = path.join(confDir, "local");
fs.mkdirSync(localStorageDir, {recursive: true});
global.localStorage = new LocalStorage(localStorageDir);
const queryClient = new QueryClient({
defaultOptions: {
queries: {

View File

@ -68,8 +68,9 @@ function UserSavedTracks() {
<PlaylistSimpleControls handlePlaylistPlayPause={handlePlaylistPlayPause} isActive={currentPlaylist?.id === userSavedPlaylistId} />
<ScrollArea style="flex: 1; border: none;">
<View style="flex: 1; flex-direction: 'column'; align-items: 'stretch';">
{userTracks?.map(({ track }) => (
{userTracks?.map(({ track }, index) => (
<TrackButton
key={index+track.id}
active={currentPlaylist?.id === userSavedPlaylistId && currentTrack?.id === track.id}
artist={track.artists.map((x) => x.name).join(", ")}
name={track.name}

View File

@ -1,10 +1,13 @@
import dotenv from "dotenv"
import { homedir } from "os";
import { join } from "path";
const env = dotenv.config({path: join(process.cwd(), ".env")}).parsed as any
export const clientId = "";
export const trace = process.argv.find(arg => arg === "--trace") ?? false;
export const redirectURI = "http://localhost:4304/auth/spotify/callback"
export const confDir = join(homedir(), ".config", "spotube")
export const cacheDir = join(homedir(), ".cache", "spotube")
export enum QueryCacheKeys{
categories="categories",

View File

@ -6,6 +6,7 @@ import { Stream } from "stream";
import { streamToBuffer } from "./streamToBuffer";
import Jimp from "jimp";
import du from "du";
import { cacheDir } from "../conf";
interface ImageDimensions {
@ -18,15 +19,15 @@ const fsm = fs.promises;
export async function getCachedImageBuffer(name: string, dims?: ImageDimensions): Promise<Buffer> {
try {
const MB_5 = 5000000; //5 Megabytes
const cacheFolder = path.join(process.cwd(), "cache", "images");
const cacheImgFolder = path.join(cacheDir, "images");
// for clearing up the cache if it reaches out of the size
const cacheName = `${isUrl(name) ? name.split("/").slice(-1)[0] : name}.cnim`;
const cachePath = path.join(cacheFolder, cacheName);
const cachePath = path.join(cacheImgFolder, cacheName);
// checking if the cached image already exists or not
if (fs.existsSync(cachePath)) {
// automatically removing cache after a certain 50 MB oversize
if ((await du(cacheFolder)) > MB_5) {
fs.rmSync(cacheFolder, { recursive: true, force: true });
if ((await du(cacheImgFolder)) > MB_5) {
fs.rmSync(cacheImgFolder, { recursive: true, force: true });
}
const cachedImg = await fsm.readFile(cachePath);
const cachedImgMeta = (await Jimp.read(cachedImg)).bitmap;
@ -35,7 +36,7 @@ export async function getCachedImageBuffer(name: string, dims?: ImageDimensions)
// images are removed and replaced with a new one
if (dims && (cachedImgMeta.height !== dims.height || cachedImgMeta.width !== dims?.width)) {
fs.rmSync(cachePath);
return await imageResizeAndWrite(cachedImg, { cacheFolder, cacheName, dims });
return await imageResizeAndWrite(cachedImg, { cacheFolder: cacheImgFolder, cacheName, dims });
}
return cachedImg;
} else {
@ -44,11 +45,11 @@ export async function getCachedImageBuffer(name: string, dims?: ImageDimensions)
// converting axios stream to buffer
const resImgBuf = await streamToBuffer(imgData);
// creating cache_dir
await fsm.mkdir(cacheFolder, { recursive: true });
await fsm.mkdir(cacheImgFolder, { recursive: true });
if (dims) {
return await imageResizeAndWrite(resImgBuf, { cacheFolder, cacheName, dims });
return await imageResizeAndWrite(resImgBuf, { cacheFolder: cacheImgFolder, cacheName, dims });
}
await fsm.writeFile(path.join(cacheFolder, cacheName), resImgBuf);
await fsm.writeFile(path.join(cacheImgFolder, cacheName), resImgBuf);
return resImgBuf;
}
} catch (error) {