Skip to content

Commit fd31381

Browse files
committed
fix style
1 parent cc4fd9c commit fd31381

File tree

6 files changed

+110
-106
lines changed

6 files changed

+110
-106
lines changed

.prettierrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
printWidth: 80,
33
singleQuote: true,
44
trailingComma: 'all',
5-
lf: 'auto',
5+
endOfLine: 'auto',
66
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@typescript-eslint/parser": "^4.7.0",
5353
"eslint": "^7.13.0",
5454
"husky": "^1.2.1",
55-
"prettier": "^2.1.2",
55+
"prettier": "^2.2.1",
5656
"ts-node": "^9.0.0",
5757
"typescript": "^4.0.5"
5858
}

schemas/stream.ts

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,55 +40,57 @@ export const schema = new Schema(
4040
},
4141
);
4242

43-
schema.pre('validate', function (
44-
this: IStreamModel,
45-
next: mongoose.HookNextFunction,
46-
) {
47-
const currentTime = new Date();
43+
schema.pre(
44+
'validate',
45+
function (this: IStreamModel, next: mongoose.HookNextFunction) {
46+
const currentTime = new Date();
4847

49-
this.duration = Math.ceil(
50-
(this.connectUpdated.valueOf() - this.connectCreated.valueOf()) / 1000,
51-
);
48+
this.duration = Math.ceil(
49+
(this.connectUpdated.valueOf() - this.connectCreated.valueOf()) / 1000,
50+
);
5251

53-
this.bitrate =
54-
this.duration > 0 ? Math.ceil((this.bytes * 8) / this.duration / 1024) : 0;
52+
this.bitrate =
53+
this.duration > 0
54+
? Math.ceil((this.bytes * 8) / this.duration / 1024)
55+
: 0;
5556

56-
if (this.isNew) {
57-
const addr = ip6addr.parse(this.ip);
57+
if (this.isNew) {
58+
const addr = ip6addr.parse(this.ip);
5859

59-
this.ip =
60-
addr.kind() === 'ipv6'
61-
? addr.toString({ format: 'v6' })
62-
: addr.toString({ format: 'v4' });
60+
this.ip =
61+
addr.kind() === 'ipv6'
62+
? addr.toString({ format: 'v6' })
63+
: addr.toString({ format: 'v4' });
6364

64-
this.totalConnectionsCount = 0;
65-
this.peakViewersCount = 0;
65+
this.totalConnectionsCount = 0;
66+
this.peakViewersCount = 0;
6667

67-
this.createdAt = currentTime;
68-
}
68+
this.createdAt = currentTime;
69+
}
6970

70-
this.updatedAt = currentTime;
71+
this.updatedAt = currentTime;
7172

72-
next();
73-
});
73+
next();
74+
},
75+
);
7476

75-
schema.pre('save', async function (
76-
this: IStreamModel,
77-
next: mongoose.HookNextFunction,
78-
) {
79-
const streamViewers = await streamService.countViewers(this);
77+
schema.pre(
78+
'save',
79+
async function (this: IStreamModel, next: mongoose.HookNextFunction) {
80+
const streamViewers = await streamService.countViewers(this);
8081

81-
this.totalConnectionsCount = streamViewers.totalConnectionsCount;
82-
this.peakViewersCount = streamViewers.peakViewersCount;
82+
this.totalConnectionsCount = streamViewers.totalConnectionsCount;
83+
this.peakViewersCount = streamViewers.peakViewersCount;
8384

84-
try {
85-
await ipService.upsert(this.ip);
86-
} catch (error) {
87-
console.log('stream_failed_to_save_ip', error);
88-
}
85+
try {
86+
await ipService.upsert(this.ip);
87+
} catch (error) {
88+
console.log('stream_failed_to_save_ip', error);
89+
}
8990

90-
return next();
91-
});
91+
return next();
92+
},
93+
);
9294

9395
schema.virtual('isLive').get(function (this: IStreamModel) {
9496
const stream =

schemas/subscriber.ts

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,49 +36,51 @@ export const schema = new Schema(
3636
},
3737
);
3838

39-
schema.pre('validate', function (
40-
this: ISubscriberModel,
41-
next: mongoose.HookNextFunction,
42-
) {
43-
const updatedAt = new Date();
39+
schema.pre(
40+
'validate',
41+
function (this: ISubscriberModel, next: mongoose.HookNextFunction) {
42+
const updatedAt = new Date();
4443

45-
if (this.isNew) {
46-
const addr = ip6addr.parse(this.ip);
44+
if (this.isNew) {
45+
const addr = ip6addr.parse(this.ip);
4746

48-
this.ip =
49-
addr.kind() === 'ipv6'
50-
? addr.toString({ format: 'v6' })
51-
: addr.toString({ format: 'v4' });
52-
}
47+
this.ip =
48+
addr.kind() === 'ipv6'
49+
? addr.toString({ format: 'v6' })
50+
: addr.toString({ format: 'v4' });
51+
}
5352

54-
this.duration = Math.ceil(
55-
(this.connectUpdated.valueOf() - this.connectCreated.valueOf()) / 1000,
56-
);
53+
this.duration = Math.ceil(
54+
(this.connectUpdated.valueOf() - this.connectCreated.valueOf()) / 1000,
55+
);
5756

58-
this.bitrate =
59-
this.duration > 0 ? Math.ceil((this.bytes * 8) / this.duration / 1024) : 0;
57+
this.bitrate =
58+
this.duration > 0
59+
? Math.ceil((this.bytes * 8) / this.duration / 1024)
60+
: 0;
6061

61-
if (this.isNew) {
62-
this.createdAt = updatedAt;
63-
}
62+
if (this.isNew) {
63+
this.createdAt = updatedAt;
64+
}
6465

65-
this.updatedAt = updatedAt;
66+
this.updatedAt = updatedAt;
6667

67-
next();
68-
});
68+
next();
69+
},
70+
);
6971

70-
schema.pre('save', async function (
71-
this: ISubscriberModel,
72-
next: mongoose.HookNextFunction,
73-
) {
74-
try {
75-
await ipService.upsert(this.ip);
76-
} catch (error) {
77-
console.log('subscriber_failed_to_save_ip', error);
78-
}
79-
80-
return next();
81-
});
72+
schema.pre(
73+
'save',
74+
async function (this: ISubscriberModel, next: mongoose.HookNextFunction) {
75+
try {
76+
await ipService.upsert(this.ip);
77+
} catch (error) {
78+
console.log('subscriber_failed_to_save_ip', error);
79+
}
80+
81+
return next();
82+
},
83+
);
8284

8385
schema.virtual('isLive').get(function (this: ISubscriberModel) {
8486
const subscribers =

schemas/user.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ export const schema = new Schema(
2323
},
2424
);
2525

26-
schema.pre('validate', function (
27-
this: IUserModel,
28-
next: mongoose.HookNextFunction,
29-
) {
30-
if (this.isNew) {
31-
this.isAdmin = false;
32-
this.isStreamer = false;
33-
this.token = uuidv4();
34-
this.streamKey = uuidv4();
35-
}
36-
37-
next();
38-
});
39-
40-
schema.pre('validate', function (
41-
this: IUserModel,
42-
next: mongoose.HookNextFunction,
43-
) {
44-
const updatedAt = new Date();
45-
46-
if (this.isNew) {
47-
this.createdAt = updatedAt;
48-
}
49-
50-
this.updatedAt = updatedAt;
51-
52-
next();
53-
});
26+
schema.pre(
27+
'validate',
28+
function (this: IUserModel, next: mongoose.HookNextFunction) {
29+
if (this.isNew) {
30+
this.isAdmin = false;
31+
this.isStreamer = false;
32+
this.token = uuidv4();
33+
this.streamKey = uuidv4();
34+
}
35+
36+
next();
37+
},
38+
);
39+
40+
schema.pre(
41+
'validate',
42+
function (this: IUserModel, next: mongoose.HookNextFunction) {
43+
const updatedAt = new Date();
44+
45+
if (this.isNew) {
46+
this.createdAt = updatedAt;
47+
}
48+
49+
this.updatedAt = updatedAt;
50+
51+
next();
52+
},
53+
);

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,10 +1897,10 @@ prelude-ls@^1.2.1:
18971897
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.2.1.tgz#debc6489d7a6e6b0e7611888cec880337d316396"
18981898
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
18991899

1900-
prettier@^2.1.2:
1901-
version "2.1.2"
1902-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
1903-
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
1900+
prettier@^2.2.1:
1901+
version "2.2.1"
1902+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
1903+
integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
19041904

19051905
process-nextick-args@~1.0.6:
19061906
version "1.0.7"

0 commit comments

Comments
 (0)