Skip to content

Commit

Permalink
Merge pull request #607 from arabcoders/dev
Browse files Browse the repository at this point in the history
Mostly minor changes on how we display changes.
  • Loading branch information
arabcoders authored Feb 4, 2025
2 parents fe1e366 + 1252e71 commit 5715b39
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 112 deletions.
52 changes: 0 additions & 52 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,58 +216,6 @@ jobs:
path: config/config.php
regex: "'version'\\s\\=\\>\\s\\'(.+?)\\'\\,"

- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install gitpython
- name: Get Branch Name from Tag
id: branch_name
run: |
TAG_NAME=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "${TAG_NAME}" ]; then
TAG_NAME=$(git rev-parse --abbrev-ref HEAD)
fi
# Assume the tag (or branch name) is in the format "branch-something".
BRANCH_NAME=$(echo "${TAG_NAME}" | cut -d '-' -f1)
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_ENV
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
echo "Detected Tag: ${TAG_NAME} on Branch: ${BRANCH_NAME}"
- name: Disable Git ref logging
run: git config --global core.logAllRefUpdates false

- name: Push CHANGELOG to gh-pages.
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
WORKTREE_DIR=gh-pages-worktree
if git show-ref --verify --quiet refs/heads/gh-pages; then
[ -d "$WORKTREE_DIR" ] && rm -rf "$WORKTREE_DIR"
git worktree add "$WORKTREE_DIR" gh-pages
else
git worktree add -B gh-pages "$WORKTREE_DIR"
fi
# (Optional) Fix file permissions on the remote ref log (Option 2)
# Uncomment the next line if you prefer to adjust permissions instead.
# sudo chmod -R a+rw ../.git/logs/refs/remotes/origin/gh-pages || true
cd "$WORKTREE_DIR"
git pull --rebase origin gh-pages || true
python .github/scripts/generate_changelog.py --repo_path ../ --changelog_path ./CHANGELOG-${BRANCH_NAME}.json --branch_name $BRANCH_NAME
git add CHANGELOG-${BRANCH_NAME}.json
git commit -m "Update Changelog for ${BRANCH_NAME}" || echo "No changes to commit"
git push origin gh-pages
dockerhub-sync-readme:
runs-on: ubuntu-latest
if: (github.event_name == 'push' && endsWith(github.ref, github.event.repository.default_branch)) || (github.event_name == 'workflow_dispatch' && github.event.inputs.update_readme == 'true')
Expand Down
71 changes: 36 additions & 35 deletions frontend/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</button>
</div>

<div class="navbar-menu" :class="{'is-active':showMenu}">
<div class="navbar-menu" :class="{ 'is-active': showMenu }">
<div class="navbar-start" v-if="hasAPISettings">
<NuxtLink class="navbar-item" to="/backends" @click.native="(e) => changeRoute(e)">
<span class="icon-text">
Expand All @@ -30,7 +30,7 @@
</NuxtLink>

<NuxtLink class="navbar-item" to="/history"
@click.native="(e) => changeRoute(e,() => dEvent('history_main_link_clicked',{'clear':true}))">
@click.native="(e) => changeRoute(e, () => dEvent('history_main_link_clicked', { 'clear': true }))">
<span class="icon-text">
<span class="icon"><i class="fas fa-history"></i></span>
<span>History</span>
Expand Down Expand Up @@ -130,24 +130,24 @@

<div class="navbar-item">
<button class="button is-dark has-tooltip-bottom" v-tooltip.bottom="'Switch to Light theme'"
v-if="'auto' === selectedTheme" @click="selectTheme('light')">
<span class="icon has-text-warning"><i class="fas fa-sun"/></span>
v-if="'auto' === selectedTheme" @click="selectTheme('light')">
<span class="icon has-text-warning"><i class="fas fa-sun" /></span>
</button>
<button class="button is-dark has-tooltip-bottom" v-tooltip.bottom="'Switch to Dark theme'"
v-if="'light' === selectedTheme" @click="selectTheme('dark')">
<span class="icon"><i class="fas fa-moon"/></span>
v-if="'light' === selectedTheme" @click="selectTheme('dark')">
<span class="icon"><i class="fas fa-moon" /></span>
</button>
<button class="button is-dark has-tooltip-bottom" v-tooltip.bottom="'Switch to auto theme'"
v-if="'dark' === selectedTheme" @click="selectTheme('auto')">
<span class="icon"><i class="fas fa-microchip"/></span>
v-if="'dark' === selectedTheme" @click="selectTheme('auto')">
<span class="icon"><i class="fas fa-microchip" /></span>
</button>
</div>

<div class="navbar-item" v-if="hasAPISettings">
<button class="button is-dark" @click="showTaskRunner = !showTaskRunner" v-tooltip="'Task Runner Status'">
<span class="icon">
<i class="fas fa-microchip"
:class="{ 'has-text-success': taskRunner.status, 'has-text-warning': !taskRunner.status}"></i>
:class="{ 'has-text-success': taskRunner.status, 'has-text-warning': !taskRunner.status }"></i>
</span>
</button>
</div>
Expand Down Expand Up @@ -186,12 +186,12 @@
<div class="field has-addons">
<div class="control is-expanded">
<input class="input" id="api_token" v-model="api_token" required placeholder="API Token..."
@keyup="api_status = false; api_response = ''"
:type="false === exposeToken ? 'password' : 'text'">
@keyup="api_status = false; api_response = ''"
:type="false === exposeToken ? 'password' : 'text'">
</div>
<div class="control">
<button type="button" class="button is-primary" @click="exposeToken = !exposeToken"
v-tooltip="'Show/Hide token'">
v-tooltip="'Show/Hide token'">
<span class="icon" v-if="!exposeToken"><i class="fas fa-eye"></i></span>
<span class="icon" v-else><i class="fas fa-eye-slash"></i></span>
</button>
Expand All @@ -218,8 +218,7 @@
<div class="field">
<div class="control">
<input class="input" id="api_url" type="url" v-model="api_url" required
placeholder="API URL... http://localhost:8081"
@keyup="api_status = false; api_response = ''">
placeholder="API URL... http://localhost:8081" @keyup="api_status = false; api_response = ''">
<p class="help">
Use <a href="javascript:void(0)" @click="setOrigin">current page URL</a>.
</p>
Expand All @@ -239,8 +238,7 @@
<div class="field">
<div class="control">
<input class="input" id="api_path" type="text" v-model="api_path" required
placeholder="API Path... /v1/api"
@keyup="api_status = false; api_response = ''">
placeholder="API Path... /v1/api" @keyup="api_status = false; api_response = ''">
<p class="help">
Use <a href="javascript:void(0)" @click="api_path = '/v1/api'">Set default API Path</a>.
</p>
Expand All @@ -255,7 +253,7 @@
<div class="field has-addons">
<div class="control is-expanded">
<input class="input" type="text" v-model="api_response" readonly disabled
:class="{'has-background-success': true===api_status,'has-background-warning': true!==api_status}">
:class="{ 'has-background-success': true === api_status, 'has-background-warning': true !== api_status }">
</div>
<div class="control">
<button type="submit" class="button is-primary" :disabled="!api_url || !api_token">
Expand Down Expand Up @@ -283,16 +281,16 @@
</div>

<div class="column is-12 mt-2">
<Message title="Information" message_class="has-background-info-90 has-text-dark"
icon="fas fa-info-circle">
<Message title="Information" message_class="has-background-info-90 has-text-dark" icon="fas fa-info-circle">
<p>
It's possible to automatically setup the API connection for this client and <strong
class="has-text-danger">ALL VISITORS</strong> by setting the following environment variable <code>WS_API_AUTO=true</code>
class="has-text-danger">ALL VISITORS</strong> by setting the following environment variable
<code>WS_API_AUTO=true</code>
in <code>/config/.env</code> file. Understand that this option <strong class="has-text-danger">PUBLICLY
EXPOSES YOUR API TOKEN</strong> to <u>ALL VISITORS</u>. Anyone who is able to reach this page will be
EXPOSES YOUR API TOKEN</strong> to <u>ALL VISITORS</u>. Anyone who is able to reach this page will be
granted access to your <code>WatchState API</code> which exposes your other media backends data including
their secrets. <strong>this option is great security risk and SHOULD NEVER be used if
<code>WatchState</code> is exposed to the internet.</strong>
<code>WatchState</code> is exposed to the internet.</strong>
</p>

<p>Please visit
Expand All @@ -309,10 +307,10 @@
</div>

<div>
<TaskRunnerStatus v-if="showTaskRunner || false === taskRunner?.status"
:status="taskRunner" @taskrunner_update="e => taskRunner = e"/>
<NuxtPage v-if="!showConnection && hasAPISettings"/>
<no-api v-if="!hasAPISettings"/>
<TaskRunnerStatus v-if="showTaskRunner || false === taskRunner?.status" :status="taskRunner"
@taskrunner_update="e => taskRunner = e" />
<NuxtPage v-if="!showConnection && hasAPISettings" />
<no-api v-if="!hasAPISettings" />
</div>

<div class="columns is-multiline is-mobile mt-3">
Expand All @@ -324,13 +322,13 @@
</div>

<div class="column is-6 is-9-mobile has-text-left">
<NuxtLink @click="loadFile = '/README.md'" v-text="'README'"/>
<NuxtLink @click="loadFile = '/README.md'" v-text="'README'" />
-
<NuxtLink @click="loadFile = '/FAQ.md'" v-text="'FAQ'"/>
<NuxtLink @click="loadFile = '/FAQ.md'" v-text="'FAQ'" />
-
<NuxtLink @click="loadFile = '/NEWS.md'" v-text="'News'"/>
<NuxtLink @click="loadFile = '/NEWS.md'" v-text="'News'" />
-
<NuxtLink to="/changelog" v-text="'ChangeLog'"/>
<NuxtLink :to="changelog_url" v-text="'ChangeLog'" />
</div>
<div class="column is-6 is-4-mobile has-text-right">
{{ api_version }} - <a href="https://github.com/arabcoders/watchstate" target="_blank">WatchState</a>
Expand All @@ -339,27 +337,27 @@

<template v-if="loadFile">
<Overlay @closeOverlay="closeOverlay" :title="loadFile">
<Markdown :file="loadFile"/>
<Markdown :file="loadFile" />
</Overlay>
</template>
</div>
</div>
</template>

<script setup>
import {ref} from 'vue'
import { ref } from 'vue'
import 'assets/css/bulma.css'
import 'assets/css/style.css'
import 'assets/css/all.css'
import {useStorage} from '@vueuse/core'
import { useStorage } from '@vueuse/core'
import request from '~/utils/request.js'
import Markdown from '~/components/Markdown.vue'
import TaskRunnerStatus from "~/components/TaskRunnerStatus.vue";
const selectedTheme = useStorage('theme', (() => window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')())
const showConnection = ref(false)
const taskRunner = ref({status: true, message: '', restartable: false})
const taskRunner = ref({ status: true, message: '', restartable: false })
const showTaskRunner = ref(false)
const real_api_url = useStorage('api_url', window.location.origin)
Expand All @@ -373,6 +371,9 @@ const api_token = ref(toRaw(real_api_token.value))
const api_status = ref(false)
const api_response = ref('Status: Unknown')
const api_version = ref()
const changelog_url = ref('/changelog')
watch(() => api_version.value, () => changelog_url.value = `/changelog?version=${api_version.value}`)
const showMenu = ref(false)
const exposeToken = ref(false)
Expand Down Expand Up @@ -520,7 +521,7 @@ const autoConfig = async () => {
headers: {
'Accept': 'application/json'
},
body: JSON.stringify({'origin': window.location.origin})
body: JSON.stringify({ 'origin': window.location.origin })
})
const json = await response.json()
Expand Down
23 changes: 13 additions & 10 deletions frontend/pages/changelog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<span class="icon-text">
<span class="icon"><i class="fas fa-code-branch"></i></span>
<span>
{{ log.tag }} <span class="subtitle" v-if="log.tag === api_version">Installed</span>
{{ log.tag }} <span class="subtitle has-text-success" v-if="log.tag === api_version">Installed</span>
</span>
</span>
</h1>
Expand All @@ -26,9 +26,12 @@
<li v-for="commit in log.commits" :key="commit.sha">
<strong>{{ ucFirst(commit.message).replace(/\.$/, "") }}.</strong> -
<small>
<span class="has-tooltip" v-tooltip="`Date: ${commit.date}`">
{{ moment(commit.date).fromNow() }}
</span></small>
<NuxtLink :to="`https://github.com/arabcoders/watchstate/commit/${commit.sha}`" target="_blank">
<span class="has-tooltip" v-tooltip="`SHA: ${commit.sha} - Date: ${commit.date}`">
{{ moment(commit.date).fromNow() }}
</span>
</NuxtLink>
</small>
</li>
</ul>
<hr v-if="index < logs.length - 1">
Expand All @@ -37,18 +40,19 @@
</div>
</template>
<script setup>
import {notification} from '~/utils/index'
import { notification } from '~/utils/index'
import moment from 'moment'
import { NuxtLink } from '#components';
useHead({title: 'Change log'})
useHead({ title: 'Change log' })
const REPO_URL = "https://arabcoders.github.io/watchstate/CHANGELOG-{branch}.json";
const REPO_URL = "https://arabcoders.github.io/watchstate/CHANGELOG-{branch}.json?version={version}";
const logs = ref([]);
const api_version = ref('master');
const branch = computed(() => {
const branch = String(api_version.value).split('-')[0] ?? 'master';
return ['master', 'dev'].includes(branch) ? branch : 'dev';
return ['master', 'dev'].includes(branch) ? branch : 'master';
});
const loadContent = async () => {
Expand All @@ -62,7 +66,7 @@ const loadContent = async () => {
}
try {
const changes = await fetch(r(REPO_URL, {branch: branch.value}));
const changes = await fetch(r(REPO_URL, { branch: branch.value, version: api_version.value }));
logs.value = await changes.json();
} catch (e) {
console.error(e);
Expand All @@ -72,4 +76,3 @@ const loadContent = async () => {
onMounted(() => loadContent());
</script>
1 change: 0 additions & 1 deletion src/API/History/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ public function list(iRequest $request): iResponse
$sql[] = 'WHERE ' . implode(' AND ', $where);
}

syslog(LOG_DEBUG, json_encode($data->getAll()));
$stmt = $db->prepare('SELECT COUNT(*) ' . implode(' ', array_map('trim', $sql)));
$stmt->execute($params);
$total = $stmt->fetchColumn();
Expand Down
44 changes: 30 additions & 14 deletions src/Libs/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,16 +789,34 @@ function getAppVersion(): string
$gitDir = ROOT_PATH . DIRECTORY_SEPARATOR . '.git' . DIRECTORY_SEPARATOR;

if (is_dir($gitDir)) {
$cmdVersion = [
'git --git-dir=%1$s describe --exact-match --tags',
'git --git-dir=%1$s rev-parse --short HEAD',
];
foreach ($cmdVersion as $cmd) {
$proc = Process::fromShellCommandline(sprintf($cmd, escapeshellarg($gitDir)));
$proc->run();
if ($proc->isSuccessful()) {
return trim(explode(PHP_EOL, $proc->getOutput())[0]);
}
try {
// Get the current branch name.
$cmdBranch = 'git --git-dir={cwd} rev-parse --abbrev-ref HEAD';
$procBranch = Process::fromShellCommandline(r($cmdBranch, ['cwd' => escapeshellarg($gitDir)]));
$procBranch->run();
$branch = $procBranch->isSuccessful() ? trim($procBranch->getOutput()) : 'unknown';

// Get the short commit hash.
$cmdCommit = 'git --git-dir={cwd} rev-parse --short HEAD';
$procCommit = Process::fromShellCommandline(r($cmdCommit, ['cwd' => escapeshellarg($gitDir)]));
$procCommit->run();
$commit = $procCommit->isSuccessful() ? trim($procCommit->getOutput()) : 'unknown';

// Get the commit date (from HEAD) in YYYYMMDD format.
// This uses "git show" with a custom date format.
$cmdDate = 'git --git-dir={cwd} show -s --format=%cd --date=format:%Y%m%d HEAD';
$procDate = Process::fromShellCommandline(r($cmdDate, ['cwd' => escapeshellarg($gitDir)]));
$procDate->run();
$commitDate = $procDate->isSuccessful() ? trim($procDate->getOutput()) : date('Ymd');

// Return the version in the format: branch-date-sha
return r('{branch}-{date}-{commit}', [
'branch' => $branch,
'date' => $commitDate,
'commit' => $commit,
]);
} catch (Throwable) {
return 'dev-master';
}
}

Expand Down Expand Up @@ -1707,13 +1725,11 @@ function isTaskWorkerRunning(string $pidFile = '/tmp/ws-job-runner.pid', bool $i
}

switch (PHP_OS) {
case 'Linux':
{
case 'Linux': {
$status = file_exists(r('/proc/{pid}/status', ['pid' => $pid]));
}
break;
case 'WINNT':
{
case 'WINNT': {
// -- Windows does not have a /proc directory so we need different way to get the status.
@exec("tasklist /FI \"PID eq {$pid}\" 2>NUL", $output);
// -- windows doesn't return 0 if the process is not found. we need to parse the output.
Expand Down

0 comments on commit 5715b39

Please sign in to comment.