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( "" + "" + "" + "" + video.name + "
" + video.description.replace(/^\s*\n/gm, "").replace(/(?:\r\n|\r|\n)/g, '
') + "" ); }); }); } $(document).ready(function () { getVideos(window); });