Initial version

This commit is contained in:
Kumi 2023-06-02 16:14:47 +00:00
commit 100a973f47
Signed by: kumi
GPG key ID: ECBCC9082395383F
5 changed files with 106 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
config.json

0
assets/main.css Normal file
View file

65
assets/main.js Normal file
View file

@ -0,0 +1,65 @@
async function getConfig(window) {
await $.getJSON("config.json", function (data) {
window.config = data;
});
}
async function authenticate(window) {
var oauth_settings;
await $.ajax({
url: window.config.peertube_api + "/oauth-clients/local",
}).done(function (data) {
oauth_settings = data;
});
await $.ajax({
url: window.config.peertube_api + "/users/token",
type: "POST",
data: {
client_id: oauth_settings.client_id,
client_secret: oauth_settings.client_secret,
grant_type: "password",
response_type: "code",
username: window.config.peertube_user,
password: window.config.peertube_password,
},
}).done(function (data) {
window.config.access_token = data.access_token;
window.config.refresh_token = data.refresh_token;
console.log(data.access_token);
});
}
async function getVideos(window) {
await getConfig(window);
await authenticate(window);
await $.ajax({
url:
window.config.peertube_api +
"/users/me/videos?sort=-createdAt",
type: "GET",
// Add bearer token to header
beforeSend: function (xhr) {
xhr.setRequestHeader(
"Authorization",
"Bearer " + window.config.access_token
);
},
})
.fail(function (data) {
console.log(data);
})
.done(function (data) {
data.data.forEach(function (video) {
$(".table").append(
"<tr><td>" +
"<a href='" + window.config.peertube_api + "/../.." + video.embedPath + "'><img src='" + window.config.peertube_api + "/../.." + video.thumbnailPath + "'></a>" +
"</td><td>" +
"<a href='" + window.config.peertube_api + "/../.." + video.embedPath + "'>" + video.name + "</a>" +
"</td></tr>"
);
});
});
}

6
config.dist.json Normal file
View file

@ -0,0 +1,6 @@
{
"peertube_api": "https://kumi.tube/api/v1",
"peertube_user": "peertube_user",
"peertube_password": "peertube_password",
"peertube_channel": "peertube_channel"
}

34
index.html Normal file
View file

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<!-- Bootstrap page for displaying a list of videos retrieved using Javascript requests -->
<head>
<meta charset="UTF-8" />
<title>Video List</title>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
/>
</head>
<body>
<!-- Displaying the list of videos -->
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Video List</h1>
<table class="table table-bordered">
<thead>
<tr>
<th>Video Thumbnail</th>
<th>Video Title</th>
</tr>
</thead>
<tbody id="video-list"></tbody>
</table>
</div>
</div>
</div>
<!-- Javascript code for retrieving the list of videos -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="assets/main.js"></script>
</body>
</html>