Skip to content

Commit

Permalink
no more vars
Browse files Browse the repository at this point in the history
  • Loading branch information
dmikey committed Jul 9, 2021
1 parent 1c9153d commit 51ce354
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 34 deletions.
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"base_url": "http://localhost:3000/",
"mongo": "mongodb://localhost:27017/gitlfs",
"port": 3000,
"store": {
"type": "siasky",
Expand Down
33 changes: 16 additions & 17 deletions src/routes/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from "lodash";
import config from "config";
import { validate } from "jsonschema";

var { Store } = require("../store");
const { Store } = require("../store");

const STORE = Store.getStore(
config.get("store.type"),
Expand All @@ -22,9 +22,9 @@ export default function (fastify: any) {
* @param {Object} object
* @returns {Object}
*/
var handleUploadObject = async function (user: any, repo: any, object: any) {
var oid = object.oid;
var size = object.size;
let handleUploadObject = async function (user: any, repo: any, object: any) {
let oid = object.oid;
let size = object.size;
fastify.log.info({ msg: "handleUploadObject", oid, size, user, repo });
return {
oid: `${oid}`,
Expand All @@ -47,20 +47,20 @@ export default function (fastify: any) {
* @param {Object} object
* @returns {Object}
*/
var handleDownloadObject = async function (
let handleDownloadObject = async function (
user: any,
repo: any,
object: any
) {
var oid = object.oid;
var size = object.size;
let oid = object.oid;
let size = object.size;
fastify.log.info({ msg: "handleDownloadObject", oid, user, repo });
var result: any = {
let result: any = {
oid: oid,
size: size,
};

var exist = await STORE.exist(user, repo, oid);
let exist = await STORE.exist(user, repo, oid);
if (exist) {
result.actions = {
download: STORE.getDownloadAction(user, repo, oid, size),
Expand All @@ -82,9 +82,9 @@ export default function (fastify: any) {
* @param {Object} object
* @returns {Object}
*/
var handleVerifyObject = async function (user: any, repo: any, object: any) {
var oid = object.oid;
var size = object.size;
let handleVerifyObject = async function (user: any, repo: any, object: any) {
let oid = object.oid;
let size = object.size;
fastify.log.info({ msg: "handleVerifyObject", oid, user, repo });
return {
oid: oid,
Expand All @@ -100,9 +100,9 @@ export default function (fastify: any) {
async function (req: any, res: any) {
// validate request body according to JSON Schema
try {
var body = req.body;
let body = req.body;
req.jsonBody = body;
var valid = validate(body, BATCH_REQUEST_SCHEMA).valid;
let valid = validate(body, BATCH_REQUEST_SCHEMA).valid;
if (!valid) {
let err: any = new Error();
err.status = 422;
Expand All @@ -111,8 +111,7 @@ export default function (fastify: any) {

res.header("Content-Type", "application/vnd.git-lfs+json");

var body = req.jsonBody;
var operation = body.operation;
let operation = body.operation;

// validate operation
if (
Expand Down Expand Up @@ -149,7 +148,7 @@ export default function (fastify: any) {
});

results = await Promise.all(yields);
var response = {
let response = {
objects: results,
};
res.code(200).send(response);
Expand Down
9 changes: 4 additions & 5 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use strict";

var config = require("config");
var jwt = require("jsonwebtoken");
var ms = require("ms");

const config = require("config");
const jwt = require("jsonwebtoken");
const ms = require("ms");
const BASE_URL = config.get("base_url");
const JWT_CONFIG = config.get("jwt");

Expand Down Expand Up @@ -148,7 +147,7 @@ export class Store {
* @param {String} [oid], empty for verify request
*/
static _generateJWTToken(action: any, user: any, repo: any, oid: any) {
var signObject = {
let signObject = {
user: user,
repo: repo,
action: action,
Expand Down
20 changes: 8 additions & 12 deletions src/store/siasky_store.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Store } from "./index";
import mongoose from "mongoose";
import FileType from "file-type";
var toArray = require("stream-to-array");

const config = require("config");
const toArray = require("stream-to-array");
const { SkynetClient } = require("@nebulous/skynet");
const {
defaultOptions,
uriSkynetPrefix,
} = require("@nebulous/skynet/src/utils");

var _FormData: any = require("form-data");
const _FormData: any = require("form-data");

mongoose.connect("mongodb://localhost:27017/gitlfs", {
mongoose.connect(config.get("mongo"), {
useNewUrlParser: true,
useUnifiedTopology: true,
});
Expand Down Expand Up @@ -63,11 +63,7 @@ db.on("error", console.error.bind(console, "connection error:"));
};

// modified to return buffer
(SkynetClient as any).prototype.downloadFile = function (
path: any,
skylink: any,
customOptions = {}
) {
(SkynetClient as any).prototype.downloadFile = function (skylink: any) {
const opts = {
...defaultOptions("/"),
};
Expand Down Expand Up @@ -103,7 +99,7 @@ export default class SiaSkyStore extends Store {
}

async put(user: any, repo: any, oid: any, stream: any) {
var self: any = this;
let self: any = this;
const size = stream.headers["content-length"];
const skylink = await self._skynet.uploadFile(
Buffer.from(stream.body, "binary")
Expand All @@ -116,10 +112,10 @@ export default class SiaSkyStore extends Store {
}

async get(user: any, repo: any, oid: any) {
var self: any = this;
let self: any = this;
const file: any = await File.find({ oid: `${oid}` });
const skylink = file[0]?.skylink.replace("sia://", "");
const fileData: any = await self._skynet.downloadFile(null, skylink);
const fileData: any = await self._skynet.downloadFile(skylink);
const fileType = await FileType.fromBuffer(fileData);
return {
fileType,
Expand Down

0 comments on commit 51ce354

Please sign in to comment.