Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno updates #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const JumperApi = require("./commands/JumperApi");
const express = require("express");
const bodyParser = require('body-parser');
import JumperApi from "./commands/JumperApi.js";
import express, { static as static2 } from "express";
import bodyParser from 'body-parser';
const { json } = bodyParser;

const app = express();

Expand All @@ -9,12 +10,12 @@ const app = express();
// snippets are going to be a little bit longer than that (200-300kb)
// 50mb is probably... somewhat gracious, but ¯\_(ツ)_/¯

app.use(bodyParser.json({limit: '50mb'}));
app.use(json({limit: '50mb'}));

// Serve our front-end HTML for audio recording

app.use(express.static("public"));
app.use("/", express.static(__dirname + "/public", { index: "index.html" }));
app.use(static2("public"));
app.use("/", static2(import.meta.dirname + "/public", { index: "index.html" }));

// Create instance of the Jumper API and wire it up to our Urls
// /active-image maps to getActiveImageKey() - returns the most recently identified image-key.
Expand All @@ -32,4 +33,4 @@ app.post("/what-song", async (request, response) => {
response.send(result);
});

module.exports = app;
export default app;
4 changes: 2 additions & 2 deletions app.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const request = require('supertest');
const app = require("./app");
import request from 'supertest';
import app from "./app.js";

describe("The App", () => {

Expand Down
2 changes: 1 addition & 1 deletion commands/ActiveImageSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class ActiveImageSelector {
}
}

module.exports = ActiveImageSelector;
export default ActiveImageSelector;
6 changes: 3 additions & 3 deletions commands/ActiveImageSelector.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const each = require('jest-each').default;
const ActiveImageSelector = require("./ActiveImageSelector");
import { expect, test } from 'vitest'
import ActiveImageSelector from "./ActiveImageSelector.js";

const sut = new ActiveImageSelector();

Expand Down Expand Up @@ -27,7 +27,7 @@ describe("ActiveImageSelector", () => {
["It's the Most Wonderful Time of the Year", "candy"],
["Rudolph the Red-Nosed Reindeer", "deer"],
["Frosty the Snowman", "frosty"]
]).it('Maps %s to %s', (song, key) => {
])('Maps %s to %s', (song, key) => {
const returnedImageKey = sut.execute(song);

expect(returnedImageKey).toBe(key);
Expand Down
6 changes: 3 additions & 3 deletions commands/JumperApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ActiveImageSelector = require("./ActiveImageSelector");
const SongDetector = require("./SongDetector");
import ActiveImageSelector from "./ActiveImageSelector.js";
import SongDetector from "./SongDetector.js";

class JumperApi {

Expand Down Expand Up @@ -37,4 +37,4 @@ class JumperApi {
ok(value) { return { status: 200, body: value } };
}

module.exports = JumperApi;
export default JumperApi;
4 changes: 2 additions & 2 deletions commands/JumperApi.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const uuid = require('uuid/v1');
const JumperApi = require("./JumperApi");
import uuid from 'uuid/v1';
import JumperApi from "./JumperApi.js";

describe("MusicToImageMapper", async () => {

Expand Down
11 changes: 5 additions & 6 deletions commands/SongDetector.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const cfg = require('../config');
const axios = require("axios");
const { StorageSharedKeyCredential } = require("@azure/storage-blob");
const { BlobServiceClient } = require("@azure/storage-blob");
const uuid = require('uuid/v1');
import cfg from '../config.js';
import axios from "axios";
import { StorageSharedKeyCredential } from "@azure/storage-blob";
import { BlobServiceClient } from "@azure/storage-blob";

class SongDetector {
constructor(config = cfg, httpClient = axios, uploadAndReturnUrl = uploadToAzureBlobStorage) {
Expand Down Expand Up @@ -50,4 +49,4 @@ const resultDoesNotContainATitle = (result) => {
typeof result.data.result.title == 'undefined' || result.data.result.title == null;
};

module.exports = SongDetector;
export default SongDetector;
2 changes: 1 addition & 1 deletion commands/SongDetector.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const SongDetector = require("./SongDetector");
import SongDetector from "./SongDetector.js";

describe("Song detector", () => {

Expand Down
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
"azure-account": "jumperstorageaccount",
"azure-containerName": "my-jumper-container",
"azure-blobStorage": "https://your-azure-storage-account.blob.core.windows.net",
Expand Down
21 changes: 21 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"tasks": {
"start": "deno run --allow-read --allow-env --allow-sys server.js",
"devserver": "deno run --watch --inspect server.js",
"debug": "deno --inspect server.js",
"test": "vitest run"
},
"imports": {
"@azure/identity": "npm:@azure/identity@^1.0.0",
"@azure/storage-blob": "npm:@azure/storage-blob@^12.24.0",
"@std/assert": "jsr:@std/assert@1",
"axios": "npm:axios@^0.19.2",
"body-parser": "npm:body-parser@^1.20.2",
"express": "npm:express@^4.19.2",
"form-data": "npm:form-data@^4.0.0",
"jimp": "npm:jimp@^0.22.12",
"supertest": "npm:supertest@^7.0.0",
"uuid": "npm:uuid@^3.4.0",
"vitest": "npm:vitest@^2.0.5"
}
}
Loading