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