mirror of
https://github.com/tiennm99/coolify.git
synced 2026-05-13 16:58:10 +00:00
cccb9a5fec
Features: - Build packs for popular frontend frameworks. It will help to understand which build packs should be chosen. Fixes: - Github queries optimized. - Save repositories to store (faster navigation). - Remove unnecessary data on dashboard requests. - Speed up static site builds with a lot. UI: - Redesign of the application deployment page. - Redesign of database deployments page.
245 lines
5.0 KiB
JavaScript
245 lines
5.0 KiB
JavaScript
import { writable, derived, readable } from 'svelte/store'
|
|
|
|
const sessionStore = {
|
|
token: window.localStorage.getItem('token') || null,
|
|
githubAppToken: null
|
|
}
|
|
|
|
function waitAtLeast (time, promise) {
|
|
const timeoutPromise = new Promise((resolve) => {
|
|
setTimeout(resolve, time)
|
|
})
|
|
return Promise.all([promise, timeoutPromise]).then((values) => values[0])
|
|
};
|
|
|
|
export const fetch = writable(
|
|
async (
|
|
url,
|
|
{ method, body, ...customConfig } = { body: null, method: null }
|
|
) => {
|
|
let headers = { 'Content-type': 'application/json; charset=UTF-8' }
|
|
if (method === 'DELETE') {
|
|
delete headers['Content-type']
|
|
}
|
|
const isGithub = url.match(/api.github.com/)
|
|
if (isGithub) {
|
|
headers = Object.assign(headers, {
|
|
Authorization: `token ${sessionStore.githubAppToken}`
|
|
})
|
|
} else {
|
|
headers = Object.assign(headers, {
|
|
Authorization: `Bearer ${sessionStore.token}`
|
|
})
|
|
}
|
|
const config = {
|
|
cache: 'no-cache',
|
|
method: method || (body ? 'POST' : 'GET'),
|
|
...customConfig,
|
|
headers: {
|
|
...headers,
|
|
...customConfig.headers
|
|
}
|
|
}
|
|
if (body) {
|
|
config.body = JSON.stringify(body)
|
|
}
|
|
// const response = await waitAtLeast(350, window.fetch(url, config))
|
|
const response = await window.fetch(url, config)
|
|
if (response.status >= 200 && response.status <= 299) {
|
|
if (response.headers.get('content-type').match(/application\/json/)) {
|
|
return await response.json()
|
|
} else if (response.headers.get('content-type').match(/text\/plain/)) {
|
|
return await response.text()
|
|
} else if (response.headers.get('content-type').match(/multipart\/form-data/)) {
|
|
return await response.formData()
|
|
} else {
|
|
return await response.blob()
|
|
}
|
|
} else {
|
|
/* eslint-disable */
|
|
if (response.status === 401) {
|
|
return Promise.reject({
|
|
code: response.status,
|
|
error: 'Unauthorized'
|
|
})
|
|
} else if (response.status >= 500) {
|
|
const error = (await response.json()).message
|
|
return Promise.reject({
|
|
code: response.status,
|
|
error: error || 'Oops, something is not okay. Are you okay?'
|
|
})
|
|
} else {
|
|
return Promise.reject({
|
|
code: response.status,
|
|
error: response.statusText
|
|
})
|
|
}
|
|
/* eslint-enable */
|
|
}
|
|
}
|
|
)
|
|
export const activePage = writable({
|
|
application: null,
|
|
new: false,
|
|
mainmenu: null
|
|
})
|
|
export const session = writable(sessionStore)
|
|
export const loggedIn = derived(session, ($session) => {
|
|
return $session.token
|
|
})
|
|
export const githubRepositories = writable([])
|
|
export const githubInstallations = writable({})
|
|
export const savedBranch = writable()
|
|
|
|
export const dateOptions = readable({
|
|
year: 'numeric',
|
|
month: 'short',
|
|
day: '2-digit',
|
|
hour: 'numeric',
|
|
minute: 'numeric',
|
|
second: 'numeric',
|
|
hour12: false
|
|
})
|
|
|
|
export const deployments = writable([])
|
|
|
|
export const initConf = writable({})
|
|
export const application = writable({
|
|
github: {
|
|
installation: {
|
|
id: null
|
|
},
|
|
app: {
|
|
id: null
|
|
}
|
|
},
|
|
repository: {
|
|
id: null,
|
|
organization: 'new',
|
|
name: 'start',
|
|
branch: null
|
|
},
|
|
general: {
|
|
deployId: null,
|
|
nickname: null,
|
|
workdir: null
|
|
},
|
|
build: {
|
|
pack: 'static',
|
|
directory: null,
|
|
command: {
|
|
build: null,
|
|
installation: null
|
|
},
|
|
container: {
|
|
name: null,
|
|
tag: null,
|
|
baseSHA: null
|
|
}
|
|
},
|
|
publish: {
|
|
directory: null,
|
|
domain: null,
|
|
path: '/',
|
|
port: null,
|
|
secrets: []
|
|
}
|
|
})
|
|
|
|
export const initialApplication = {
|
|
github: {
|
|
installation: {
|
|
id: null
|
|
},
|
|
app: {
|
|
id: null
|
|
}
|
|
},
|
|
repository: {
|
|
id: null,
|
|
organization: null,
|
|
name: null,
|
|
branch: null
|
|
},
|
|
general: {
|
|
deployId: null,
|
|
nickname: null,
|
|
workdir: null
|
|
},
|
|
build: {
|
|
pack: 'static',
|
|
directory: null,
|
|
command: {
|
|
build: null,
|
|
installation: null
|
|
},
|
|
container: {
|
|
name: null,
|
|
tag: null
|
|
}
|
|
},
|
|
publish: {
|
|
directory: null,
|
|
domain: null,
|
|
path: '/',
|
|
port: null,
|
|
secrets: []
|
|
}
|
|
}
|
|
export const initialDatabase = {
|
|
config: {
|
|
general: {
|
|
workdir: null,
|
|
deployId: null,
|
|
nickname: null,
|
|
type: null
|
|
},
|
|
database: {
|
|
username: null,
|
|
passwords: [],
|
|
defaultDatabaseName: null
|
|
},
|
|
deploy: {
|
|
name: null
|
|
}
|
|
},
|
|
envs: {}
|
|
}
|
|
|
|
export const database = writable({
|
|
config: {
|
|
general: {
|
|
workdir: null,
|
|
deployId: null,
|
|
nickname: null,
|
|
type: null
|
|
},
|
|
database: {
|
|
username: null,
|
|
passwords: [],
|
|
defaultDatabaseName: null
|
|
},
|
|
deploy: {
|
|
name: null
|
|
}
|
|
},
|
|
envs: {}
|
|
})
|
|
|
|
export const dbInprogress = writable(false)
|
|
|
|
export const newService = writable({
|
|
email: null,
|
|
userName: 'admin',
|
|
userPassword: null,
|
|
userPasswordAgain: null,
|
|
baseURL: null
|
|
})
|
|
export const initialNewService = {
|
|
email: null,
|
|
userName: 'admin',
|
|
userPassword: null,
|
|
userPasswordAgain: null,
|
|
baseURL: null
|
|
}
|