Skip to content

Commit 179f369

Browse files
committed
Checkpoint: tests are passing
This required a few ts-ignores and I'm sure that a lot of this is still broken, but the tests are green so we're gonna call it a day. Next step will be to verify that we can actually run the server, and that the express middleware still works after the version updates Then we have to reimplement the build process, and then we can work on refactoring to use sharp instead of gm.
1 parent 0f47a60 commit 179f369

File tree

13 files changed

+100
-66
lines changed

13 files changed

+100
-66
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"devDependencies": {
2929
"@types/express": "^4.16.1",
30+
"@types/gm": "^1.18.2",
3031
"@types/mocha": "^5.2.6",
3132
"@types/node": "^11.13.4",
3233
"@types/serve-favicon": "^2.2.30",

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import routes from './routes/avatars';
2+
3+
export default routes;
File renamed without changes.
File renamed without changes.

src/lib/imager.js renamed to src/lib/imager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const combine = (face, size, callback) => {
2727
size = { width: maxSize, height: maxSize };
2828
}
2929

30-
imageMagick()
30+
imageMagick('')
3131
.quality(0)
3232
.in(face.eyes)
3333
.in(face.nose)

src/lib/potato.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/lib/potato.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// our libs
2+
import { sumAndDiff } from './hashingFunctions';
3+
import { allPaths } from './imageFiles';
4+
import SlotMachine from './slotMachine';
5+
6+
const colors = [
7+
'#81bef1',
8+
'#ad8bf2',
9+
'#bff288',
10+
'#de7878',
11+
'#a5aac5',
12+
'#6ff2c5',
13+
'#f0da5e',
14+
'#eb5972',
15+
'#f6be5d'
16+
];
17+
18+
class Potato {
19+
constructor(
20+
private colorMachine = new SlotMachine(colors),
21+
private eyesMachine = new SlotMachine(allPaths('eyes')),
22+
private noseMachine = new SlotMachine(allPaths('nose')),
23+
private mouthMachine = new SlotMachine(allPaths('mouth'), sumAndDiff)
24+
) {}
25+
26+
// Construct Faces Parts
27+
parts(string) {
28+
return {
29+
color: this.colorMachine.pull(string),
30+
eyes: this.eyesMachine.pull(string),
31+
nose: this.noseMachine.pull(string),
32+
mouth: this.mouthMachine.pull(string)
33+
};
34+
}
35+
}
36+
37+
export default new Potato();

src/lib/slotMachine.js renamed to src/lib/slotMachine.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { sum } from './hashingFunctions';
22

3-
class SlotMachine {
4-
constructor(slots, hashingFn) {
3+
class SlotMachine<T> {
4+
private slots: T[];
5+
private numSlots: number;
6+
private hashingFn: (items: number[]) => number;
7+
8+
constructor(slots: T[], hashingFn?) {
59
this.slots = slots;
610
this.numSlots = this.slots.length;
711
this.hashingFn = hashingFn || sum;

src/routes/avatars.js renamed to src/routes/avatars.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import potato from '../lib/potato';
88

99
const partTypes = ['eyes', 'nose', 'mouth'];
1010

11-
// eslint-disable-next-line new-cap
1211
const router = Router();
1312

1413
router.param('id', function(req, res, next, id) {
1514
var faceParts;
1615
faceParts = potato.parts(id);
16+
//@ts-ignore
1717
req.faceParts = faceParts;
1818
return next();
1919
});
@@ -31,6 +31,7 @@ router.get('/list', function(req, res) {
3131
router.get('/:size?/random', function(req, res) {
3232
var faceParts;
3333
faceParts = potato.parts(uuid.v4());
34+
//@ts-ignore
3435
req.faceParts = faceParts;
3536

3637
return combine(faceParts, req.params.size, function(err, stdout) {
@@ -39,6 +40,7 @@ router.get('/:size?/random', function(req, res) {
3940
});
4041

4142
router.get('/:size?/:id', function(req, res, next) {
43+
//@ts-ignore
4244
return combine(req.faceParts, req.params.size, function(err, stdout) {
4345
return common.sendImage(err, stdout, req, res, next);
4446
});

0 commit comments

Comments
 (0)