Skip to content

A self-hosted media server and file management system

fix: code smells

aminnausinb6b58ce467a8
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 705c2c5b..e521b463 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -90,7 +90,7 @@ jobs:
# ---------- PHP Setup ----------
- name: Setup PHP
- uses: shivammathur/setup-php@v2
+ uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240
with:
php-version: ${{ matrix.php }}
extensions: json, dom, curl, libxml, mbstring, pgsql
diff --git a/app/Console/Commands/GenerateManifest.php b/app/Console/Commands/GenerateManifest.php
index fb3b1a3e..cc9963d3 100644
--- a/app/Console/Commands/GenerateManifest.php
+++ b/app/Console/Commands/GenerateManifest.php
@@ -11,15 +11,12 @@ class GenerateManifest extends Command {
protected $description = 'Generate the current Git version and commit hash to a manifest';
public function handle() {
- $staticCommit = (file_exists(base_path('COMMIT')) ? trim(file_get_contents(base_path('COMMIT'))) : env('GITHUB_SHA', ''));
+ $staticCommit = (file_exists(base_path('COMMIT')) ? trim(file_get_contents(base_path('COMMIT'))) : env('GITHUB_SHA', 'unknown'));
+ $staticVersion = (file_exists(base_path('VERSION')) ? trim(file_get_contents(base_path('VERSION'))) : env('GITHUB_REF_NAME', 'unknown'));
- $commit = trim(shell_exec('git rev-parse --short HEAD') ?? '')
- ?: substr($staticCommit, 0, 7)
- ?: 'unknown';
+ $commit = trim(shell_exec('git rev-parse --short HEAD') ?? '') ?: substr($staticCommit, 0, 7);
- $version = trim(shell_exec('git describe --tags --abbrev=0') ?? '')
- ?: (file_exists(base_path('VERSION')) ? trim(file_get_contents(base_path('VERSION'))) : null)
- ?: env('GITHUB_REF_NAME', 'unknown');
+ $version = trim(shell_exec('git describe --tags --abbrev=0') ?? '') ?: $staticVersion;
$data = json_encode([
'version' => $version,
@@ -41,4 +38,8 @@ class GenerateManifest extends Command {
return Command::FAILURE;
}
}
+
+ private function getVersionFromFile(): ?string {
+ return file_exists(base_path('VERSION')) ? trim(file_get_contents(base_path('VERSION'))) : null;
+ }
}
diff --git a/changelog.sh b/changelog.sh
index cc517fb4..607918ac 100644
--- a/changelog.sh
+++ b/changelog.sh
@@ -1,10 +1,12 @@
+#!/bin/bash
+
CURRENT_TAG=$(git describe --tags --abbrev=0 HEAD)
DEFAULT_PREVIOUS_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG^" 2>/dev/null)
read -p "Previous Tag [$DEFAULT_PREVIOUS_TAG]: " USER_TAG
-if [ "$USER_TAG" = "-" ]; then
+if [[ "$USER_TAG" = "-" ]]; then
PREVIOUS_TAG=""
else
PREVIOUS_TAG=${USER_TAG:-$DEFAULT_PREVIOUS_TAG}
@@ -13,7 +15,7 @@ fi
echo "Current tag: $CURRENT_TAG"
echo "Previous tag: $PREVIOUS_TAG"
-if [ -z "$PREVIOUS_TAG" ]; then
+if [[ -z "$PREVIOUS_TAG" ]]; then
echo "No previous tag found, generating full changelog"
COMMIT_RANGE=""
else
@@ -35,7 +37,7 @@ echo "" >> "$CHANGELOG_FILE"
echo "## What's Changed" >> "$CHANGELOG_FILE"
echo "" >> "$CHANGELOG_FILE"
-if [ -z "$COMMIT_RANGE" ]; then
+if [[ -z "$COMMIT_RANGE" ]]; then
COMMITS=$(git log --pretty=format:"%s %h" --no-merges)
else
COMMITS=$(git log --pretty=format:"%s %h" --no-merges $COMMIT_RANGE)
@@ -49,13 +51,13 @@ write_section() {
MATCHES=$(printf "%s\n" "$COMMITS" | grep -E "$PATTERN" || true)
# if there are matches, write out with scope under the title
- if [ -n "$MATCHES" ]; then
+ if [[ -n "$MATCHES" ]]; then
echo "### $TITLE" >> $CHANGELOG_FILE
echo "" >> $CHANGELOG_FILE
printf "%s\n" "$MATCHES" | while IFS=$'\t' read -r msg hash; do
scope=$(echo "$msg" | sed -nE 's/^[a-zA-Z_]+!?\(([^)]+)\):.*/\1/p')
- if [ -n "$scope" ]; then
+ if [[ -n "$scope" ]]; then
scope="**$scope:** "
fi
@@ -84,13 +86,13 @@ write_section "◀️ Reverts" "^revert(\(.+\))?:"
# write breaking section separately to handle commits and commit descriptions
BREAKING=$(echo "$COMMITS" | grep -E "^[a-z_]+!|BREAKING CHANGE" || true)
-if [ -n "$BREAKING" ]; then
+if [[ -n "$BREAKING" ]]; then
echo "### 🚨 Breaking Changes" >> $CHANGELOG_FILE
echo "" >> $CHANGELOG_FILE
printf "%s\n" "$BREAKING" | while IFS=$'\t' read -r msg hash; do
scope=$(echo "$msg" | sed -nE 's/^[a-zA-Z_]+!?\(([^)]+)\):.*/\1/p')
- if [ -n "$scope" ]; then
+ if [[ -n "$scope" ]]; then
scope="**$scope:** "
fi
diff --git a/docker/entrypoint.d/1-keys.sh b/docker/entrypoint.d/1-keys.sh
index ffc6eb99..6013d81e 100644
--- a/docker/entrypoint.d/1-keys.sh
+++ b/docker/entrypoint.d/1-keys.sh
@@ -2,7 +2,7 @@
set -e
-if [ -z "$APP_KEY" ] || [ "$APP_KEY" = "base64:" ]; then
+if [[ -z "$APP_KEY" ]] || [[ "$APP_KEY" = "base64:" ]]; then
echo "No APP_KEY detected, generating one..."
php artisan key:generate
else
@@ -13,7 +13,7 @@ SHARED_ENV_FILE=/var/www/html/shared/env
LARAVEL_ENV_FILE=/var/www/html/.env
TMP_FILE=/var/www/html/shared/.shared_env.tmp
-if [ ! -f "$SHARED_ENV_FILE" ]; then
+if [[ ! -f "$SHARED_ENV_FILE" ]]; then
echo "Generating REVERB keys..."
diff --git a/resources/js/components/video/VideoPlayer.vue b/resources/js/components/video/VideoPlayer.vue
index e487ab2e..c4504bfb 100755
--- a/resources/js/components/video/VideoPlayer.vue
+++ b/resources/js/components/video/VideoPlayer.vue
@@ -534,9 +534,9 @@ const handleProgress = (override = false) => {
const progress = player.value.currentTime / player.value.duration;
- if (isNaN(progress) || !progress) return;
+ if (Number.isNaN(progress) || !progress) return;
- progressCache.value = [...progressCache.value, { metadata_id: stateVideo.value?.metadata?.id, progress: parseFloat(progress.toFixed(2)) * 1000 }];
+ progressCache.value = [...progressCache.value, { metadata_id: stateVideo.value?.metadata?.id, progress: Number.parseFloat(progress.toFixed(2)) * 1000 }];
if (progressCache.value.length >= playbackDataBuffer || override) {
createPlayback({ entries: progressCache.value });
@@ -983,7 +983,7 @@ function resetPlayerInfo() {
const handleLoadSavedVolume = () => {
const savedVolume = parseFloat(localStorage.getItem('videoVolume') ?? '');
- if (isNaN(savedVolume) || !player.value) {
+ if (Number.isNaN(savedVolume) || !player.value) {
handleVolumeChange();
return;
}
@@ -1280,17 +1280,17 @@ onMounted(() => {
if (document.pictureInPictureElement) document.exitPictureInPicture();
handleLoadSavedVolume();
handleMediaSessionEvents();
- window.addEventListener('keydown', handleKeyBinds);
+ globalThis.addEventListener('keydown', handleKeyBinds);
document.addEventListener('fullscreenchange', handleFullScreenChange);
- window.addEventListener('pointerup', stopScrub);
- window.addEventListener('contextmenu', stopScrub);
+ globalThis.addEventListener('pointerup', stopScrub);
+ globalThis.addEventListener('contextmenu', stopScrub);
unSub = onSeek(handleManualSeek);
});
onBeforeUnmount(() => {
- window.removeEventListener('pointerup', stopScrub);
- window.removeEventListener('contextmenu', stopScrub);
- window.removeEventListener('keydown', handleKeyBinds);
+ globalThis.removeEventListener('pointerup', stopScrub);
+ globalThis.removeEventListener('contextmenu', stopScrub);
+ globalThis.removeEventListener('keydown', handleKeyBinds);
document.removeEventListener('fullscreenchange', handleFullScreenChange);
if (unSub) unSub();
diff --git a/resources/js/service/queries.ts b/resources/js/service/queries.ts
index 00c075a5..b3105d6a 100644
--- a/resources/js/service/queries.ts
+++ b/resources/js/service/queries.ts
@@ -26,7 +26,7 @@ export const useVideoPlayback = (idRef: Ref<number, number>) => {
return useQuery({
queryKey: ['videoPlayback', idRef],
queryFn: async () => {
- if (isNaN(idRef.value)) return [];
+ if (Number.isNaN(idRef.value)) return [];
const { data: response } = await mediaAPI.getPlayback(idRef.value);
return response;
},
diff --git a/resources/js/service/util.ts b/resources/js/service/util.ts
index c946bdc5..c8e16d92 100644
--- a/resources/js/service/util.ts
+++ b/resources/js/service/util.ts
@@ -80,7 +80,7 @@ export function toFormattedDate(
}
export function toFormattedDuration(rawSeconds: number = 0, leadingZero: boolean = true, format: 'digital' | 'analog' | 'verbose' = 'analog', rounded = false) {
- if (isNaN(Number(rawSeconds))) return null;
+ if (Number.isNaN(Number(rawSeconds))) return null;
const hours = Math.floor(rawSeconds / 3600);
const minutes = Math.floor((rawSeconds % 3600) / 60);
diff --git a/resources/js/service/wsService.ts b/resources/js/service/wsService.ts
index 47097ffb..eac5603d 100644
--- a/resources/js/service/wsService.ts
+++ b/resources/js/service/wsService.ts
@@ -10,7 +10,7 @@ import { toast } from '@aminnausin/cedar-ui';
* @param taskId The specific Task ID
*/
export function subscribeToTask(taskId: number, options?: { onComplete?: (event: any) => void; toastOptions?: ToastOptions }) {
- if (isNaN(taskId) || taskId <= 0 || window.Echo == null) return;
+ if (Number.isNaN(taskId) || taskId <= 0 || window.Echo == null) return;
const channelName = `tasks.${taskId}`;
diff --git a/resources/js/stores/DashboardStore.ts b/resources/js/stores/DashboardStore.ts
index fc15729b..911e6889 100644
--- a/resources/js/stores/DashboardStore.ts
+++ b/resources/js/stores/DashboardStore.ts
@@ -34,7 +34,7 @@ export const useDashboardStore = defineStore('Dashboard', () => {
if (!v?.data) return;
const totalSize = v.data.reduce((total: number, library: CategoryResource) => total + library.total_size, 0);
- if (!isNaN(totalSize)) stateTotalLibrariesSize.value = formatFileSize(totalSize);
+ if (!Number.isNaN(totalSize)) stateTotalLibrariesSize.value = formatFileSize(totalSize);
});
watch(rawUsers, (v) => {
@@ -56,14 +56,14 @@ export const useDashboardStore = defineStore('Dashboard', () => {
});
watch(rawActiveSessions, (v: any) => {
- if (isNaN(parseInt(v))) return;
+ if (Number.isNaN(Number.parseInt(v))) return;
stateActiveSessions.value = v ?? 0;
});
watch(
() => route?.params?.id,
(URL_ID) => {
- stateLibraryId.value = parseInt(`${URL_ID}`) && parseInt(`${URL_ID}`) > 0 ? parseInt(`${URL_ID}`) : -1; // ISSUE: using -1 as an empty value
+ stateLibraryId.value = Number.parseInt(`${URL_ID}`) && Number.parseInt(`${URL_ID}`) > 0 ? Number.parseInt(`${URL_ID}`) : -1; // ISSUE: using -1 as an empty value
},
{ immediate: true },
);