assets: Run ts-standard
This commit is contained in:
parent
ef4ed86bc2
commit
78976d0179
27 changed files with 155 additions and 157 deletions
|
|
@ -2,4 +2,4 @@ import 'purecss/build/pure.css'
|
|||
import 'purecss/build/grids-responsive.css'
|
||||
|
||||
import '~/src/lib/pure-toggle-menu'
|
||||
import './index.css'
|
||||
import './index.css'
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ const iipserver = document.getElementById('iipserver') as HTMLInputElement
|
|||
system.addEventListener('submit', (evt) => {
|
||||
evt.preventDefault()
|
||||
|
||||
const flavorElement = document.querySelector('input[name="flavor"]:checked');
|
||||
const flavor = (flavorElement instanceof HTMLInputElement) ? flavorElement.value : "";
|
||||
const flavorElement = document.querySelector('input[name="flavor"]:checked')
|
||||
const flavor = (flavorElement instanceof HTMLInputElement) ? flavorElement.value : ''
|
||||
|
||||
Provision({
|
||||
Slug: slug.value,
|
||||
Provision({
|
||||
Slug: slug.value,
|
||||
Flavor: flavor,
|
||||
System: { PHP: php.value, IIPServer: iipserver.checked, OpCacheDevelopment: opcacheDevelopment.checked, ContentSecurityPolicy: contentSecurityPolicy.value }
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,86 +1,85 @@
|
|||
/** @file provides a list of websocket calls supported by the backend */
|
||||
|
||||
import type { CallSpec } from ".";
|
||||
import type { CallSpec } from '.'
|
||||
|
||||
/** Backup backups everything */
|
||||
export function Backup(): CallSpec {
|
||||
return {
|
||||
'call': 'backup',
|
||||
'params': [],
|
||||
}
|
||||
export function Backup (): CallSpec {
|
||||
return {
|
||||
call: 'backup',
|
||||
params: []
|
||||
}
|
||||
}
|
||||
|
||||
type ProvisionParams = {
|
||||
Slug: string;
|
||||
Flavor?: "Drupal 10" | "Drupal 9",
|
||||
IIPServer?: string,
|
||||
System: SystemParams
|
||||
interface ProvisionParams {
|
||||
Slug: string
|
||||
Flavor?: 'Drupal 10' | 'Drupal 9'
|
||||
IIPServer?: string
|
||||
System: SystemParams
|
||||
}
|
||||
|
||||
type SystemParams = {
|
||||
PHP: "Default (8.1)" | "8.0" | "8.1" | "8.2",
|
||||
OpCacheDevelopment: boolean,
|
||||
ContentSecurityPolicy: string,
|
||||
interface SystemParams {
|
||||
PHP: 'Default (8.1)' | '8.0' | '8.1' | '8.2'
|
||||
OpCacheDevelopment: boolean
|
||||
ContentSecurityPolicy: string
|
||||
}
|
||||
|
||||
/** Provision provisions a new instance */
|
||||
export function Provision(params: ProvisionParams): CallSpec {
|
||||
return {
|
||||
'call': 'provision',
|
||||
'params': [
|
||||
JSON.stringify(params)
|
||||
],
|
||||
}
|
||||
export function Provision (params: ProvisionParams): CallSpec {
|
||||
return {
|
||||
call: 'provision',
|
||||
params: [
|
||||
JSON.stringify(params)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/** Snapshot makes a snapshot of an instance */
|
||||
export function Snapshot(Slug: string): CallSpec {
|
||||
return {
|
||||
'call': 'snapshot',
|
||||
'params': [Slug],
|
||||
}
|
||||
export function Snapshot (Slug: string): CallSpec {
|
||||
return {
|
||||
call: 'snapshot',
|
||||
params: [Slug]
|
||||
}
|
||||
}
|
||||
|
||||
/** Rebuild rebuilds an instance */
|
||||
export function Rebuild(Slug: string, params: SystemParams): CallSpec {
|
||||
return {
|
||||
'call': 'rebuild',
|
||||
'params': [
|
||||
Slug,
|
||||
JSON.stringify(params)
|
||||
],
|
||||
}
|
||||
export function Rebuild (Slug: string, params: SystemParams): CallSpec {
|
||||
return {
|
||||
call: 'rebuild',
|
||||
params: [
|
||||
Slug,
|
||||
JSON.stringify(params)
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/** Update updates a specific instance */
|
||||
export function Update(Slug: string): CallSpec {
|
||||
return {
|
||||
'call': 'update',
|
||||
'params': [Slug],
|
||||
}
|
||||
export function Update (Slug: string): CallSpec {
|
||||
return {
|
||||
call: 'update',
|
||||
params: [Slug]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Start starts a specific instance */
|
||||
export function Start(Slug: string): CallSpec {
|
||||
return {
|
||||
'call': 'start',
|
||||
'params': [Slug],
|
||||
}
|
||||
export function Start (Slug: string): CallSpec {
|
||||
return {
|
||||
call: 'start',
|
||||
params: [Slug]
|
||||
}
|
||||
}
|
||||
|
||||
/** Stop stops a specific instance */
|
||||
export function Stop(Slug: string): CallSpec {
|
||||
return {
|
||||
'call': 'stop',
|
||||
'params': [Slug],
|
||||
}
|
||||
export function Stop (Slug: string): CallSpec {
|
||||
return {
|
||||
call: 'stop',
|
||||
params: [Slug]
|
||||
}
|
||||
}
|
||||
|
||||
/** Purge purges a specific instance */
|
||||
export function Purge(Slug: string): CallSpec {
|
||||
return {
|
||||
'call': 'purge',
|
||||
'params': [Slug],
|
||||
}
|
||||
export function Purge (Slug: string): CallSpec {
|
||||
return {
|
||||
call: 'purge',
|
||||
params: [Slug]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
/** @file implements the websocket protocol used by the distillery */
|
||||
|
||||
import { default as WebSocket } from "isomorphic-ws"
|
||||
import { Buffer } from "buffer";
|
||||
import WebSocket from 'isomorphic-ws'
|
||||
import { Buffer } from 'buffer'
|
||||
|
||||
/** Call represents a specific WebSocket call */
|
||||
export default class Call {
|
||||
constructor(remote: Remote, spec: CallSpec) {
|
||||
constructor (remote: Remote, spec: CallSpec) {
|
||||
this.remote = remote
|
||||
this.call = spec
|
||||
}
|
||||
|
||||
|
||||
public readonly remote: Readonly<Remote>
|
||||
public readonly call: Readonly<CallSpec>
|
||||
|
||||
|
|
@ -36,39 +35,38 @@ export default class Call {
|
|||
* Connect to the specified remote endpoint and perform the action
|
||||
* @param remote Remote to connect to
|
||||
*/
|
||||
connect(): Promise<Result> {
|
||||
async connect (): Promise<Result> {
|
||||
// ensure that connect is only run once.
|
||||
if (this.connected) {
|
||||
throw new Error('connect() may only be called once')
|
||||
}
|
||||
this.connected = true
|
||||
|
||||
// and do the connection!
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// and do the connection!
|
||||
return await new Promise((resolve, reject) => {
|
||||
// create the websocket
|
||||
const ws = new WebSocket(this.remote.url, this.remote.token ? { 'headers': { 'Authorization': 'Bearer ' + this.remote.token } } : undefined)
|
||||
const ws = new WebSocket(this.remote.url, typeof this.remote.token === 'string' ? { headers: { Authorization: 'Bearer ' + this.remote.token } } : undefined)
|
||||
this.ws = ws // make it available to other things
|
||||
|
||||
|
||||
// result is a promise, because some APIs in the browser are async
|
||||
let result = Promise.resolve(JSON.stringify({'success': false, 'message': 'Unknown error'}))
|
||||
let result = Promise.resolve(JSON.stringify({ success: false, message: 'Unknown error' }))
|
||||
|
||||
ws.onopen = () => {
|
||||
if (this.beforeCall) {
|
||||
this.beforeCall.call(this)
|
||||
if (this.beforeCall != null) {
|
||||
this.beforeCall()
|
||||
}
|
||||
ws.send(Buffer.from(JSON.stringify(this.call), 'utf8'))
|
||||
}
|
||||
|
||||
|
||||
ws.onmessage = ({ data }) => {
|
||||
// if this is a string it is a log line
|
||||
if (typeof data === 'string') {
|
||||
if (this.onLogLine) {
|
||||
this.onLogLine.call(this, data)
|
||||
if (this.onLogLine != null) {
|
||||
this.onLogLine(data)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// decode the message
|
||||
if (data instanceof Blob) {
|
||||
result = data.text()
|
||||
|
|
@ -82,57 +80,58 @@ export default class Call {
|
|||
this.close()
|
||||
|
||||
// call the handler and reject
|
||||
if (this.onError) {
|
||||
this.onError.call(this, err)
|
||||
if (this.onError != null) {
|
||||
this.onError(err)
|
||||
}
|
||||
reject(err)
|
||||
}
|
||||
|
||||
|
||||
ws.onclose = () => {
|
||||
this.close()
|
||||
|
||||
|
||||
// decode the result
|
||||
result
|
||||
.then(t => JSON.parse(t))
|
||||
.then((res) => {
|
||||
if (this.afterCall) {
|
||||
this.afterCall.call(this, res)
|
||||
if (this.afterCall != null) {
|
||||
this.afterCall(res)
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
.catch((e) => console.error(e))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/** sendText sends some text to the server requests cancellation of an ongoing operation */
|
||||
sendText(text: string) {
|
||||
const ws = this.ws
|
||||
if (ws == null) {
|
||||
throw new Error('websocket not connected')
|
||||
}
|
||||
|
||||
ws.send(text)
|
||||
}
|
||||
|
||||
/** cancel requests cancellation of an ongoing operation */
|
||||
cancel() {
|
||||
sendText (text: string): void {
|
||||
const ws = this.ws
|
||||
if (ws == null) {
|
||||
throw new Error('websocket not connected')
|
||||
}
|
||||
|
||||
ws.send(Buffer.from(JSON.stringify({ signal: 'cancel'}), 'utf8'))
|
||||
ws.send(text)
|
||||
}
|
||||
|
||||
/** cancel requests cancellation of an ongoing operation */
|
||||
cancel (): void {
|
||||
const ws = this.ws
|
||||
if (ws == null) {
|
||||
throw new Error('websocket not connected')
|
||||
}
|
||||
|
||||
ws.send(Buffer.from(JSON.stringify({ signal: 'cancel' }), 'utf8'))
|
||||
}
|
||||
|
||||
/** close closes this websocket connection */
|
||||
private close() {
|
||||
private close (): void {
|
||||
const ws = this.ws
|
||||
if (ws == null) {
|
||||
throw new Error('websocket not connected')
|
||||
}
|
||||
|
||||
ws.close()
|
||||
this.ws = null;
|
||||
this.ws = null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +141,7 @@ export interface Remote {
|
|||
token?: string // optional token
|
||||
}
|
||||
|
||||
/** CallSpec represents the specification for a call*/
|
||||
/** CallSpec represents the specification for a call */
|
||||
export interface CallSpec {
|
||||
call: string
|
||||
params: string[]
|
||||
|
|
@ -150,6 +149,6 @@ export interface CallSpec {
|
|||
|
||||
/** the result of a websocket call */
|
||||
export interface Result {
|
||||
success: boolean,
|
||||
message: string,
|
||||
success: boolean
|
||||
message: string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
import './index.css';
|
||||
import './index.css'
|
||||
|
||||
const WINDOW_CHANGE_EVENT = ('onorientationchange' in window) ? 'orientationchange' : 'resize';
|
||||
const WINDOW_CHANGE_EVENT = ('onorientationchange' in window) ? 'orientationchange' : 'resize'
|
||||
|
||||
document.querySelectorAll('.pure-toggle-menu').forEach((menu) => {
|
||||
const toggle = menu.querySelector('.toggle');
|
||||
if (!toggle) {
|
||||
console.warn("'.pure-toggle-menu' without '.toggle'");
|
||||
return;
|
||||
}
|
||||
const toggle = menu.querySelector('.toggle')
|
||||
if (toggle == null) {
|
||||
console.warn("'.pure-toggle-menu' without '.toggle'")
|
||||
return
|
||||
}
|
||||
|
||||
const toggleMenu = () => {
|
||||
menu.classList.toggle('closed');
|
||||
toggle.classList.toggle('x');
|
||||
};
|
||||
const toggleMenu = (): void => {
|
||||
menu.classList.toggle('closed')
|
||||
toggle.classList.toggle('x')
|
||||
}
|
||||
|
||||
toggle.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
toggleMenu();
|
||||
});
|
||||
toggle.addEventListener('click', (e) => {
|
||||
e.preventDefault()
|
||||
toggleMenu()
|
||||
})
|
||||
|
||||
window.addEventListener(WINDOW_CHANGE_EVENT, () => {
|
||||
if (menu.classList.contains('closed')) return;
|
||||
toggleMenu();
|
||||
});
|
||||
});
|
||||
window.addEventListener(WINDOW_CHANGE_EVENT, () => {
|
||||
if (menu.classList.contains('closed')) return
|
||||
toggleMenu()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -219,21 +219,21 @@ export function createModal (action: string, params: string[], opts: Partial<Mod
|
|||
const call = new LocalCall({
|
||||
call: action,
|
||||
params
|
||||
});
|
||||
})
|
||||
|
||||
call.beforeCall = function() {
|
||||
call.beforeCall = function () {
|
||||
cancelButton.removeAttribute('disabled')
|
||||
cancelButton.addEventListener('click', (event) => {
|
||||
event.preventDefault()
|
||||
cancelButton.addEventListener('click', (event) => {
|
||||
event.preventDefault()
|
||||
|
||||
print('^C\n', true)
|
||||
this.cancel()
|
||||
})
|
||||
print(' Connected.\n', true)
|
||||
print('^C\n', true)
|
||||
this.cancel()
|
||||
})
|
||||
print(' Connected.\n', true)
|
||||
}
|
||||
call.onLogLine = print;
|
||||
call.onLogLine = print
|
||||
|
||||
call.connect()
|
||||
.then((result) => close(result))
|
||||
.catch(() => close({ success: false, message: 'connection closed unexpectedly' }));
|
||||
.catch(() => close({ success: false, message: 'connection closed unexpectedly' }))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { default as Call, CallSpec } from '../apiclient/websocket';
|
||||
import Call, { CallSpec } from '../apiclient/websocket'
|
||||
|
||||
/** LocalCall is like Call, but uses the current page */
|
||||
export default class LocalCall extends Call {
|
||||
constructor(spec: CallSpec) {
|
||||
super({ url: location.protocol.replace('http', 'ws') + '//' + location.host + '/api/v1/ws'}, spec);
|
||||
}
|
||||
}
|
||||
constructor (spec: CallSpec) {
|
||||
super({ url: location.protocol.replace('http', 'ws') + '//' + location.host + '/api/v1/ws' }, spec)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue