feat: add "mark as broken"
This commit is contained in:
parent
198fec613a
commit
fba9fc8d78
2 changed files with 66 additions and 32 deletions
|
@ -10,12 +10,14 @@ if (!$exists) {
|
|||
url TEXT NOT NULL,
|
||||
audio BOOLEAN NOT NULL CHECK (audio IN (0, 1)),
|
||||
video BOOLEAN NOT NULL CHECK (video IN (0, 1)),
|
||||
ts NUMBER
|
||||
ts NUMBER,
|
||||
works BOOLEAN NOT NULL CHECK (works IN (0, 1))
|
||||
);
|
||||
EOD);
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
||||
switch ($_SERVER['REQUEST_METHOD']) {
|
||||
case "POST":
|
||||
$data = json_decode(file_get_contents('php://input'));
|
||||
|
||||
$url = $data->url;
|
||||
|
@ -23,7 +25,7 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||
$video = $data->video;
|
||||
|
||||
if ($url !== null && $audio !== null && $video !== null) {
|
||||
$stmt = $db->prepare('INSERT INTO links (url, audio, video, ts) VALUES (:url, :audio, :video, :ts);');
|
||||
$stmt = $db->prepare('INSERT INTO links (url, audio, video, ts, works) VALUES (:url, :audio, :video, :ts, TRUE);');
|
||||
$stmt->bindValue(':url', $url);
|
||||
$stmt->bindValue(':audio', $audio);
|
||||
$stmt->bindValue(':video', $video);
|
||||
|
@ -39,10 +41,16 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||
http_response_code(400);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
case "DELETE":
|
||||
$stmt = $db->prepare('UPDATE links SET works=0 WHERE id=:id');
|
||||
$stmt->bindValue(':id', $_GET["id"], SQLITE3_INTEGER);
|
||||
$stmt->execute();
|
||||
break;
|
||||
default:
|
||||
$result = [];
|
||||
|
||||
$db_result = $db->query("SELECT * FROM links;");
|
||||
$db_result = $db->query("SELECT * FROM links WHERE works != 0;");
|
||||
while ($row = $db_result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$row["audio"] = $row["audio"] == 1;
|
||||
$row["video"] = $row["video"] == 1;
|
||||
|
@ -51,4 +59,5 @@ if ($_SERVER['REQUEST_METHOD'] == "POST") {
|
|||
|
||||
header('Content-type: application/json; charset=utf-8');
|
||||
echo json_encode($result);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<script>
|
||||
import { Link } from "svelte-navigator";
|
||||
import { Link, useNavigate } from "svelte-navigator";
|
||||
import { onMount } from "svelte";
|
||||
import Spinner from "./components/Spinner.svelte";
|
||||
const navigate = useNavigate();
|
||||
|
||||
export let audioId;
|
||||
export let videoId;
|
||||
|
@ -115,6 +116,18 @@
|
|||
videoPlayer.mute();
|
||||
audioPlayer.playVideo();
|
||||
}
|
||||
|
||||
async function onBroken(id) {
|
||||
const result = await fetch(`grid.php?id=${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
if (result.ok) {
|
||||
alert(`ID ${id} marked as broken, thanks!`);
|
||||
navigate("/");
|
||||
} else {
|
||||
alert(`ERR: ${result.status} ${result.statusText}`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<main>
|
||||
|
@ -129,9 +142,15 @@
|
|||
<h2 title={videoUrl}>Video</h2>
|
||||
{#if !videoReady}<Spinner />{/if}
|
||||
<div id="videoPlayer" bind:this={videoEl} />
|
||||
<a class="broken" href="javascript:;" on:click={() => onBroken(videoId)}
|
||||
>broken?</a
|
||||
>
|
||||
<h2 title={audioUrl}>Audio</h2>
|
||||
{#if !audioReady}<Spinner />{/if}
|
||||
<div id="audioPlayer" bind:this={audioEl} />
|
||||
<a class="broken" href="javascript:;" on:click={() => onBroken(audioId)}
|
||||
>broken?</a
|
||||
>
|
||||
</div>
|
||||
|
||||
<Link class="link" to="/">BACK</Link>
|
||||
|
@ -166,6 +185,12 @@
|
|||
height: 128px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: red;
|
||||
opacity: 0.5;
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
color: gray;
|
||||
cursor: not-allowed;
|
||||
|
|
Loading…
Reference in a new issue