Move API_ORIGIN into constants.js

This commit is contained in:
Johannes Zellner
2025-03-03 11:22:56 +01:00
parent 6c674e86e5
commit ef0a9a4a1e
37 changed files with 196 additions and 217 deletions
+3 -4
View File
@@ -1,6 +1,7 @@
import moment from 'moment';
import { ansiToHtml } from 'anser';
import { API_ORIGIN } from '../constants.js';
// https://github.com/janl/mustache.js/blob/master/mustache.js#L60
const entityMap = {
@@ -26,8 +27,6 @@ function ab2str(buf) {
export function create(type, id) {
const accessToken = localStorage.token;
const origin = import.meta.env.VITE_API_ORIGIN || window.location.origin;
const INITIAL_STREAM_LINES = 100;
let eventSource = null;
@@ -57,7 +56,7 @@ export function create(type, id) {
return {
name: 'LogsModel',
stream(lineHandler, errorHandler) {
eventSource = new EventSource(`${origin}${streamApi}?lines=${INITIAL_STREAM_LINES}&access_token=${accessToken}`);
eventSource = new EventSource(`${API_ORIGIN}${streamApi}?lines=${INITIAL_STREAM_LINES}&access_token=${accessToken}`);
eventSource._lastMessage = null;
eventSource.onerror = function ( /* uselessError */) {
if (eventSource.readyState === EventSource.CLOSED) {
@@ -87,7 +86,7 @@ export function create(type, id) {
};
},
getDownloadUrl() {
return `${origin}${downloadApi}?access_token=${accessToken}&format=short&lines=-1`;
return `${API_ORIGIN}${downloadApi}?access_token=${accessToken}&format=short&lines=-1`;
}
};
}