Skip to content

Commit

Permalink
fix more code-style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Apr 4, 2022
1 parent 6ff9cd8 commit 343db4c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion frontend/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const apiBase = "/api/v1";

export async function apiRequest(req: string, body: object, method = "POST") {
let resp = await fetch(`${apiBase}/${req}`, {
method: method,
method,
mode: "cors",
headers: {
"Content-Type": "application/json"
Expand Down
20 changes: 12 additions & 8 deletions frontend/src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class Chart {
}

protected pointsPositions(points: Point[], bounds: Bounds): Point[] {
return points.map(e => {
return points.map((e) => {
const map = (value: number, inMin: number, inMax: number, outMin: number, outMax: number): number => {
return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
};
Expand All @@ -31,7 +31,7 @@ export class Chart {
const y = map(e[1], bounds.yMin, bounds.yMax, 27, 3);

return [x, y];
})
});
}

protected line(pointA: Point, pointB: Point): Line {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class Chart {
protected bezierCommand(point: Point, i: number, a: Point[]): string {
const cps = this.controlPoint(a[i - 1], a[i - 2], point);
const cpe = this.controlPoint(point, a[i - 1], a[i + 1], true);
const close = i === a.length - 1 ? ' z':'';
const close = i === a.length - 1 ? " z" : "";

return `C ${cps[0]},${cps[1]} ${cpe[0]},${cpe[1]} ${point[0]},${point[1]}${close}`;
}
Expand All @@ -69,7 +69,7 @@ export class Chart {
const d = points.reduce((acc, e, i, a) => i === 0
? `M ${a[a.length - 1][0]},100 L ${e[0]},100 L ${e[0]},${e[1]}`
: `${acc} ${this.bezierCommand(e, i, a)}`
, '');
, "");

return `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 1 100 30"><path d="${d}" /></svg>`;
}
Expand All @@ -83,15 +83,19 @@ export class Chart {
};

for (let p of points) {
if (p[1] > options.yMax)
if (p[1] > options.yMax) {
options.yMax = p[1];
if (p[1] < options.yMin)
}
if (p[1] < options.yMin) {
options.yMin = p[1];
}

if (p[0] > options.xMax)
if (p[0] > options.xMax) {
options.xMax = p[0];
if (p[0] < options.xMin)
}
if (p[0] < options.xMin) {
options.xMin = p[0];
}
}

return options;
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Tooltip } from "bootstrap";

import "../css/index.scss";

import '@fortawesome/fontawesome-free/js/fontawesome';
import '@fortawesome/fontawesome-free/js/solid';
import "@fortawesome/fontawesome-free/js/fontawesome";
import "@fortawesome/fontawesome-free/js/solid";

import prettyBytes from "pretty-bytes";
import * as prettyMilliseconds from "pretty-ms";
Expand All @@ -20,7 +20,7 @@ var progressBar: ProgressBar;
var config: Config;
var chart: Chart;
var upload: Upload | null;
let points: Array<number[]> = []
let points: Array<number[]> = [];

function reset() {
if (upload && upload.inProgress) {
Expand Down Expand Up @@ -84,13 +84,13 @@ function alert(cls: string, msg: string, url?: string, icon?: string) {
tooltip.dispose();
btnCopy.title = "Copy to clipboard";
tooltip = new Tooltip(btnCopy);
}, 1000)
}, 1000);
});
}
}

function uploadStarted(upload: Upload) {
let msg: string = upload.stage == "hashing"
let msg: string = upload.stage === "hashing"
? "Hashing in progress"
: "Uploading in progress";

Expand Down Expand Up @@ -125,7 +125,7 @@ function uploadEnded(upload: Upload) {

statsBytes.textContent = prettyBytes(p.totalTransferred);
statsTime.textContent = prettyMilliseconds(p.totalElapsed, { compact: true });
statsTimeETA.textContent = '0 s';
statsTimeETA.textContent = "0 s";

progressBar.set(p.totalSize);
}
Expand Down Expand Up @@ -235,8 +235,9 @@ async function fileChanged(ev: Event) {
ev.preventDefault();

let tgt = ev.target as HTMLInputElement;
if (tgt === null || tgt.files === null)
return
if (tgt === null || tgt.files === null) {
return;
}

await startUpload(tgt.files);
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Upload {
try {
this.inProgress = true;

if (this.file.size == 0) {
if (this.file.size === 0) {
throw "Cannot upload empty file";
}

Expand Down Expand Up @@ -168,7 +168,7 @@ export class Upload {

this.url = respInitiate.url;

let existingParts: {[x: number]: Part} = {}
let existingParts: {[x: number]: Part} = {};
for (let part of respInitiate.parts) {
existingParts[part.number] = Part.fromJSON(part);
}
Expand All @@ -195,7 +195,7 @@ export class Upload {
checksum: buf2hex(part.etag),
length: part.length,
number: part.number
})
});

let etag = await this.uploadPart(partResp.url, chunk);
if (!this.file) {
Expand Down Expand Up @@ -249,7 +249,7 @@ export class Upload {

this.xhr.onabort = () => {
reject("Aborted");
}
};

this.xhr.upload.onprogress = (ev) => this.progress.partProgress(ev);
this.xhr.upload.onloadstart = (ev) => this.progress.partStart(ev);
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
// DefaultMaxUploadSize is the maximum upload size if not provided by the configuration
DefaultMaxUploadSize size = 1e12 // 1TB

// Is the default S3 region if not provided by the configuration
// DefaultRegion is the default S3 region if not provided by the configuration
DefaultRegion = "us-east-1"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type configResponse struct {
Features featureResponse `json:"features"`
}

// HandleConfig returns runtime configuration to the frontend
// HandleConfigWith returns runtime configuration to the frontend
func HandleConfigWith(version, commit, date string) func(*gin.Context) {
return func(c *gin.Context) {
cfg := c.MustGet("config").(*config.Config)
Expand Down

0 comments on commit 343db4c

Please sign in to comment.