Skip to content

Commit

Permalink
trying to skip linting
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonhochkins committed Jul 3, 2024
1 parent 9a79b04 commit ce41072
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 28 deletions.
2 changes: 1 addition & 1 deletion hakit/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Hakit",
"version": "1.0.19",
"version": "1.0.20",
"slug": "hakit",
"init": false,
"ingress": true,
Expand Down
14 changes: 13 additions & 1 deletion hakit/server/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,25 @@ <h1>EXPERIMENTAL - DO NOT USE THIS, enable "custom_dashboard" in the configurati
<button onclick="downloadAsset()">Download zip file</button>
<button onclick="runApplication()">Run & Build Application</button>
<button onclick="checkApplicationStatus()">Check Application Status</button>
<button onclick="getAddonInfo()">Get Addon Info</button>
<h2>Write to File</h2>
<input type="text" id="filename" placeholder="Filename" value="service-account.json" />
<textarea id="fileContent" rows="10" placeholder="File content"></textarea>
<button onclick="writeToFile()">Write to File</button>

<script>
const baseUrl = window.location.origin + window.location.pathname;
let baseUrl = window.location.origin;

function getAddonInfo() {
fetch(`${baseUrl}get-addon-info`, {
method: 'POST'
})
.then(response => response.text())
.then(data => {
alert(data);
})
.catch(error => console.error('Error:', error));
}

function checkApplicationStatus() {
fetch(`${baseUrl}status`, {
Expand Down
2 changes: 2 additions & 0 deletions hakit/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getAvailableVersions } from './routes/get-available-versions.js';
import { downloadVersion } from './routes/download-version.js';
import { runApplication } from './routes/run-application.js';
import { writeFile } from './routes/write-file.js';
import { getAddonInfo } from './routes/get-addon-info.js';

/***************************************************************************************************************************
* Load Environment Values
Expand Down Expand Up @@ -88,6 +89,7 @@ async function loadConfig() {
const runApplicationRequest = await runApplication(app);
app.post('/run-application', runApplicationRequest);
app.post('/write-file', writeFile);
app.post('/get-addon-info', getAddonInfo);

} else {
app.get('/', async (_req, res) => {
Expand Down
105 changes: 105 additions & 0 deletions hakit/server/routes/get-addon-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { Request, Response } from 'express';
import axios from 'axios';
import { translateError } from 'server/helpers/index.js';

interface Data {
name?: string;
slug?: string;
hostname?: string;
dns?: string[];
description?: string;
long_description?: string;
advanced?: boolean;
stage?: string;
repository?: string;
version_latest?: string;
protected?: boolean;
rating?: number;
boot?: string;
options?: {
html_file_path?: string;
spa_mode?: boolean;
custom_dashboard?: boolean;
};
schema?: Array<{
name?: string;
required?: boolean;
type?: string;
}>;
arch?: string[];
machine?: any[];
homeassistant?: any;
url?: string | null;
detached?: boolean;
available?: boolean;
build?: boolean;
network?: any;
network_description?: any;
host_network?: boolean;
host_pid?: boolean;
host_ipc?: boolean;
host_uts?: boolean;
host_dbus?: boolean;
privileged?: any[];
full_access?: boolean;
apparmor?: string;
icon?: boolean;
logo?: boolean;
changelog?: boolean;
documentation?: boolean;
stdin?: boolean;
hassio_api?: boolean;
hassio_role?: string;
auth_api?: boolean;
homeassistant_api?: boolean;
gpio?: boolean;
usb?: boolean;
uart?: boolean;
kernel_modules?: boolean;
devicetree?: boolean;
udev?: boolean;
docker_api?: boolean;
video?: boolean;
audio?: boolean;
startup?: string;
services?: any[];
discovery?: any[];
translations?: Record<string, any>;
ingress?: boolean;
signed?: boolean;
state?: string;
webui?: any;
ingress_entry?: string;
ingress_url?: string;
ingress_port?: number;
ingress_panel?: boolean;
audio_input?: any;
audio_output?: any;
auto_update?: boolean;
ip_address?: string;
version?: string;
update_available?: boolean;
watchdog?: boolean;
devices?: any[];
}


export async function getAddonInfo(_req: Request, res: Response) {
// Function to get the ingress URL from Home Assistant API
try {
const response = await axios.get<{
data: Data;
}>('http://hassio/addons/self/info', {
headers: {
'Authorization': `Bearer ${process.env.SUPERVISOR_TOKEN}`
}
});
return res.send({
status: typeof response?.data?.data !== 'undefined' ? 'success' : 'error',
data: response?.data?.data
});
} catch (error) {
console.error('Error fetching ingress URL:', translateError(error));
}
return null;
}
29 changes: 3 additions & 26 deletions hakit/server/routes/run-application.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Request, Response } from 'express';
import { Express } from 'express';
import axios from 'axios';
import next from 'next';
import { join } from 'path';
import { existsSync, readFileSync } from 'fs';
Expand Down Expand Up @@ -57,7 +56,7 @@ export async function runApplication(app: Express) {
let version: string | null = null;
try {
const packageJsonPath = join(APP_DIRECTORY, 'app', 'package.json');
// check if the above ppath exists
// check if the above path exists
const packageJSONExists = existsSync(packageJsonPath);
if (!packageJSONExists) {
version = null;
Expand All @@ -75,43 +74,21 @@ export async function runApplication(app: Express) {
version: string | null;
built: boolean;
running: boolean;
ingressUrl: string | null;
} = {
version,
built: nextJsBuilt,
running: isAppRunning,
ingressUrl: null,
};

// Function to get the ingress URL from Home Assistant API
const getIngressUrl = async (): Promise<string | null> => {
try {
const response = await axios.get('http://hassio/addons/self/info', {
headers: {
'Authorization': `Bearer ${process.env.SUPERVISOR_TOKEN}`
}
});
console.log('response', JSON.stringify(response.data, null, 2));
if (response.data && response.data.data && response.data.data.ingress_url) {
return response.data.data.ingress_url;
}
} catch (error) {
console.error('Error fetching ingress URL:', translateError(error));
}
return null;
};
const data = await getIngressUrl();
status.ingressUrl = data;

res.json(status);
});

return async (_req: Request, res: Response) => {
const nextJsBuilt = existsSync(join(APP_DIRECTORY, 'app', '.next'));
try {
if (!nextJsBuilt) {
const installDependencies = `cd ${join(APP_DIRECTORY, 'app')} && npm i`;
const buildNextApp = `cd ${join(APP_DIRECTORY, 'app')} && npm run build`;
const installDependencies = `cd ${join(APP_DIRECTORY, 'app')} && npm ci`;
const buildNextApp = `cd ${join(APP_DIRECTORY, 'app')} && SKIP_LINTING=true SKIP_TYPE_CHECKING=true npm run build`;

try {
console.log('Installing dependencies');
Expand Down

0 comments on commit ce41072

Please sign in to comment.