Skip to content

Commit

Permalink
remove /api/v1 prefix in ui routes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdumetz committed Jul 11, 2024
1 parent 6af5b5f commit 6ab6988
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 168 deletions.
1 change: 0 additions & 1 deletion source/ui/MainView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import "./composants/Modal";
import "./screens/List";
import "./screens/Admin";
import "./screens/SceneHistory";
import "./screens/FileHistory";
import "./screens/UserSettings";
import "./screens/Home";
import "./screens/Tags";
Expand Down
2 changes: 1 addition & 1 deletion source/ui/composants/UserLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import Notification from "./Notification";
ev.preventDefault();
const username = ev.target["username"].value;
this.active = true;
fetch(`/api/v1/login/${username}/link`, {
fetch(`/auth/login/${username}/link`, {
method: "POST",
}).then(async (r)=>{
if(!r.ok){
Expand Down
4 changes: 2 additions & 2 deletions source/ui/screens/Admin/AdminArchives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface User {

fetchScenes() : void{
this.loading = true;
fetch("/api/v1/scenes?access=none")
fetch("/scenes?access=none")
.then(HttpError.okOrThrow)
.then(async (r)=>{
this.list = (await r.json()).scenes;
Expand All @@ -61,7 +61,7 @@ interface User {

onDeleteScene = (ev :MouseEvent, s :Scene)=>{
ev.preventDefault();
fetch(`/api/v1/scenes/${s.name}?archive=false`, {
fetch(`/scenes/${s.name}?archive=false`, {
headers: {"Content-Type": "application/json"},
method: "DELETE"
}).then(HttpError.okOrThrow)
Expand Down
4 changes: 2 additions & 2 deletions source/ui/screens/Admin/AdminHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class TestmailModalBody extends i18n(LitElement){
protected render(): unknown {
let onsend = ()=>{
this.state = "sending";
fetch("/api/v1/admin/mailtest", {method: "POST"}).then(async (r)=>{
fetch("/admin/mailtest", {method: "POST"}).then(async (r)=>{
let msg = await r.text();
if(r.ok){
this.state = "OK: "+msg;
Expand Down Expand Up @@ -73,7 +73,7 @@ export default class AdminHomeScreen extends i18n(LitElement) {
<h3>${this.t("ui.tools")}</h3>
<ul>
<li>
<a download href="/api/v1/scenes?format=zip">${this.t("ui.downloadZip")}</a>
<a download href="/scenes?format=zip">${this.t("ui.downloadZip")}</a>
</li>
<li>
<a href="" @click=${(e)=>{
Expand Down
4 changes: 2 additions & 2 deletions source/ui/screens/Admin/AdminStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class AdminStatsScreen extends i18n(LitElement) {
scenes :{mtime:string, name:string}[] =[];

fetchStats(){
fetch("/api/v1/admin/stats", {
fetch("/admin/stats", {
headers:{"Accept":"application/json"}
}).then(async r=>{
let b = await r.json();
Expand All @@ -35,7 +35,7 @@ export default class AdminStatsScreen extends i18n(LitElement) {
}

fetchScenes(){
fetch("/api/v1/scenes", {
fetch("/scenes", {
headers:{"Accept":"application/json"}
}).then(async r=>{
let b = await r.json();
Expand Down
8 changes: 4 additions & 4 deletions source/ui/screens/Admin/UsersList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface User {

fetchUsers() : void{
this.loading = true;
fetch("/api/v1/users")
fetch("/users")
.then(HttpError.okOrThrow)
.then(async (r)=>{
this.list = await r.json();
Expand All @@ -65,7 +65,7 @@ interface User {
(ev.target as HTMLFormElement).reset();
Modal.close();
console.log("create user : ", username, password, isAdministrator, email);
fetch("/api/v1/users", {
fetch("/users", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({username, password, isAdministrator, email})
Expand All @@ -81,7 +81,7 @@ interface User {
}
onDeleteUser = (ev :MouseEvent, u :User)=>{
ev.preventDefault();
fetch(`/api/v1/users/${u.uid}`, {
fetch(`/users/${u.uid}`, {
headers: {"Content-Type": "application/json"},
method: "DELETE"
}).then(HttpError.okOrThrow)
Expand Down Expand Up @@ -180,7 +180,7 @@ interface User {
</div>`;
}
createLoginLink(u :User){
fetch(`/api/v1/login/${u.username}/link`, {
fetch(`/auth/login/${u.username}/link`, {
method: "GET",
headers: {
"Content-Type": "text/plain"
Expand Down
138 changes: 0 additions & 138 deletions source/ui/screens/FileHistory.ts

This file was deleted.

2 changes: 1 addition & 1 deletion source/ui/screens/Home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ interface Upload{
setError({code: xhr.status, message: xhr.statusText});
}

xhr.open('POST', as_scenes? `/api/v1/scenes`:`/api/v1/scenes/${name}`);
xhr.open('POST', as_scenes? `/scenes`:`/scenes/${name}`);
xhr.send(file);
})();
}
Expand Down
4 changes: 2 additions & 2 deletions source/ui/screens/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ interface Upload{
setError({code: xhr.status, message: xhr.statusText});
}

xhr.open('POST', as_scenes? `/api/v1/scenes`:`/api/v1/scenes/${name}`);
xhr.open('POST', as_scenes? `/scenes`:`/scenes/${name}`);
xhr.send(file);
})();
}
Expand Down Expand Up @@ -190,7 +190,7 @@ interface Upload{
${(this.selection.length)?html`
<div class="section">
<h4 style="margin-top:0">${this.t("ui.tools")}</h4>
<a class="btn btn-main btn-icon" download href="/api/v1/scenes?${
<a class="btn btn-main btn-icon" download href="/scenes?${
this.selection.map(name=>`name=${encodeURIComponent(name)}`).join("&")
}&format=zip">
Download Zip
Expand Down
16 changes: 8 additions & 8 deletions source/ui/screens/SceneHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SceneVersion{

async fetchScene(){
const signal = this.#c.signal;
await fetch(`/api/v1/scenes/${encodeURIComponent(this.name)}`, {signal}).then(async (r)=>{
await fetch(`/scenes/${encodeURIComponent(this.name)}`, {signal}).then(async (r)=>{
if(!r.ok) throw new Error(`[${r.status}]: ${r.statusText}`);
let body = await r.json();
if(signal.aborted) return;
Expand All @@ -134,7 +134,7 @@ class SceneVersion{

async fetchPermissions(){
const signal = this.#c.signal;
await fetch(`/api/v1/scenes/${encodeURIComponent(this.name)}/permissions`, {signal}).then(async (r)=>{
await fetch(`/auth/access/${encodeURIComponent(this.name)}`, {signal}).then(async (r)=>{
if(!r.ok) throw new Error(`[${r.status}]: ${r.statusText}`);
let body = await r.json();
if(signal.aborted) return;
Expand All @@ -148,7 +148,7 @@ class SceneVersion{

async fetchHistory(){
const signal = this.#c.signal;
await fetch(`/api/v1/scenes/${encodeURIComponent(this.name)}/history`, {signal}).then(async (r)=>{
await fetch(`/history/${encodeURIComponent(this.name)}`, {signal}).then(async (r)=>{
if(!r.ok) throw new Error(`[${r.status}]: ${r.statusText}`);
let body = await r.json();
if(signal.aborted) return;
Expand Down Expand Up @@ -216,7 +216,7 @@ class SceneVersion{
<ui-icon name="edit"></ui-icon> ${this.t("ui.editScene")}
</a>`:null}
<a class="btn btn-main" style="margin-top:10px" href=${`/ui/scenes/${scene}/view`}><ui-icon name="eye"></ui-icon> ${this.t("ui.viewScene")}</a>
<a class="btn btn-main" style="margin-top:10px" download href="/api/v1/scenes/${scene}?format=zip"><ui-icon name="save"></ui-icon> ${this.t("ui.downloadScene")}</a>
<a class="btn btn-main" style="margin-top:10px" download href="/scenes/${scene}?format=zip"><ui-icon name="save"></ui-icon> ${this.t("ui.downloadScene")}</a>
</div>
</div>
Expand All @@ -238,7 +238,7 @@ class SceneVersion{


async setTags(tags :string[]){
return await fetch(`/api/v1/scenes/${encodeURIComponent(this.name)}`, {
return await fetch(`/scenes/${encodeURIComponent(this.name)}`, {
method: "PATCH",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({tags})
Expand Down Expand Up @@ -380,7 +380,7 @@ class SceneVersion{
console.log("Restore : ", i);
Notification.show(`Restoring to ${i.name}#${i.generation}...`, "info");
this.versions = null;
fetch(`/api/v1/scenes/${encodeURIComponent(this.name)}/history/`, {
fetch(`/history/${encodeURIComponent(this.name)}`, {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(i)
Expand All @@ -394,7 +394,7 @@ class SceneVersion{

async grant(username :string, access :AccessRights["access"]){
if(access == "none" && username != "default") access = null;
let p = fetch(`/api/v1/scenes/${encodeURIComponent(this.name)}/permissions`, {
let p = fetch(`/auth/access/${encodeURIComponent(this.name)}`, {
method: "PATCH",
headers:{"Content-Type":"application/json"},
body: JSON.stringify({username:username, access:access})
Expand Down Expand Up @@ -449,7 +449,7 @@ class SceneVersion{
header: this.t("ui.renameScene"),
body: html`<div style="display:block;position:relative;padding-top:110px"><spin-loader visible></spin-loader></div>`,
});
fetch(`/api/v1/scenes/${encodeURIComponent(this.name)}`, {
fetch(`/scenes/${encodeURIComponent(this.name)}`, {
method:"PATCH",
headers:{"Content-Type":"application/json"},
body: JSON.stringify({name})
Expand Down
4 changes: 2 additions & 2 deletions source/ui/screens/Tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class TagsScreen extends withUser(LitElement){

async fetchTags(){
const signal = this.#c.signal;
await fetch(`/api/v1/tags`, {signal}).then(async (r)=>{
await fetch(`/tags`, {signal}).then(async (r)=>{
if(!r.ok) throw new Error(`[${r.status}]: ${r.statusText}`);
let body = await r.json();
if(signal.aborted) return;
Expand All @@ -73,7 +73,7 @@ export default class TagsScreen extends withUser(LitElement){
this.scenes = [];
if(this.selected === -1 ) return;
const signal = this.#c.signal;
await fetch(`/api/v1/tags/${encodeURIComponent(this.tags[this.selected].name)}`, {signal}).then(async (r)=>{
await fetch(`/tags/${encodeURIComponent(this.tags[this.selected].name)}`, {signal}).then(async (r)=>{
if(!r.ok) throw new Error(`[${r.status}]: ${r.statusText}`);
let body = await r.json();
if(signal.aborted) return;
Expand Down
2 changes: 1 addition & 1 deletion source/ui/screens/UserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class UserSettings extends i18n(withUser(LitElement)) {
if(!Object.keys(patch).length){
return Notification.show("Nothing to change", "info");
}
fetch(`/api/v1/users/${this.user.uid}`, {
fetch(`/users/${this.user.uid}`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
Expand Down
6 changes: 3 additions & 3 deletions source/ui/state/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function setSession(s ?:UserSession){
}

export async function doLogin(username :string, password :string) :Promise<void>{
await fetch("/api/v1/login", {
await fetch("/auth/login", {
method: "POST",
headers:{
"Content-Type":"application/json",
Expand All @@ -35,7 +35,7 @@ export async function doLogin(username :string, password :string) :Promise<void>
}

export async function updateLogin(){
let r = await fetch("/api/v1/login", {
let r = await fetch("/auth/login", {
method : "GET",
headers:{"Accept": "application/json"}
});
Expand All @@ -46,7 +46,7 @@ export async function updateLogin(){
}

export async function doLogout(){
let r = await fetch("/api/v1/logout", {
let r = await fetch("/auth/logout", {
method : "POST",
headers:{"Accept": "application/json"}
});
Expand Down
Loading

0 comments on commit 6ab6988

Please sign in to comment.