Add temporary links
Fixes #4. Also removes statistics since those have been replaced by GoatCounter anyway.
This commit is contained in:
parent
7e96b63a86
commit
9370724b35
|
@ -23,7 +23,6 @@ $needs_confirmation = false;
|
||||||
try {
|
try {
|
||||||
$links = new Links(".links.db", "links.sql");
|
$links = new Links(".links.db", "links.sql");
|
||||||
list($target, $needs_confirmation) = $links->getTarget($path);
|
list($target, $needs_confirmation) = $links->getTarget($path);
|
||||||
$links->handleVisit($path);
|
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
$error = true;
|
$error = true;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +62,7 @@ if ($target != null && !$needs_confirmation) {
|
||||||
<h3>Internal server error</h3>
|
<h3>Internal server error</h3>
|
||||||
<p>Something went wrong internally, and you could not be redirected. Please try again later.</p>
|
<p>Something went wrong internally, and you could not be redirected. Please try again later.</p>
|
||||||
<?php
|
<?php
|
||||||
} else if ($target != null && $needs_confirmation) {
|
} else if ($needs_confirmation) {
|
||||||
?>
|
?>
|
||||||
<h3>Confirm redirect</h3>
|
<h3>Confirm redirect</h3>
|
||||||
<p>This URL redirects to <b><?= $target ?></b>.</p>
|
<p>This URL redirects to <b><?= $target ?></b>.</p>
|
||||||
|
@ -107,7 +106,7 @@ if ($target != null && !$needs_confirmation) {
|
||||||
$("#header").appendChild(header({title: "fwdkr.co"}));
|
$("#header").appendChild(header({title: "fwdkr.co"}));
|
||||||
$("#footer").appendChild(footer({
|
$("#footer").appendChild(footer({
|
||||||
vcsURL: "https://git.fwdekker.com/FWDekker/fwdkr.co/",
|
vcsURL: "https://git.fwdekker.com/FWDekker/fwdkr.co/",
|
||||||
version: "v1.3.4"
|
version: "v1.4.0"
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -28,6 +28,8 @@ class Links
|
||||||
$this->db = new SQLite3($database, SQLITE3_OPEN_READWRITE);
|
$this->db = new SQLite3($database, SQLITE3_OPEN_READWRITE);
|
||||||
}
|
}
|
||||||
$this->db->enableExceptions(true);
|
$this->db->enableExceptions(true);
|
||||||
|
|
||||||
|
$this->deleteExpiredLinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,15 +59,12 @@ class Links
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the visit counter and visit date of the given path.
|
* Deletes all expired links.
|
||||||
*
|
|
||||||
* @param string $path the path to handle a visit to
|
|
||||||
*/
|
*/
|
||||||
function handleVisit(string $path)
|
function deleteExpiredLinks(): void {
|
||||||
{
|
$now = date("Y-m-d H:i:s");
|
||||||
$stmt = $this->db->prepare("UPDATE links SET visits = visits + 1, last_visit = CURRENT_TIMESTAMP
|
$stmt = $this->db->prepare("DELETE FROM links WHERE expires_at < :now;");
|
||||||
WHERE path = :path;");
|
$stmt->bindValue(":now", $now);
|
||||||
$stmt->bindValue(":path", $path);
|
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,8 @@ create table links
|
||||||
constraint links_pk
|
constraint links_pk
|
||||||
primary key,
|
primary key,
|
||||||
target text not null,
|
target text not null,
|
||||||
needs_confirmation boolean default false not null,
|
needs_confirmation boolean default false not null,
|
||||||
visits int default 0 not null,
|
expires_at datetime default null
|
||||||
last_visit text
|
|
||||||
);
|
);
|
||||||
|
|
||||||
create unique index links_path_uindex
|
create unique index links_path_uindex
|
||||||
|
|
Loading…
Reference in New Issue