Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v1.1.0
- Loading branch information
Showing
10 changed files
with
293 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { Document } from 'camo' | ||
|
||
/** | ||
* Type : | ||
* v: episodes view | ||
* d: episodes download | ||
* a: show add | ||
* r: show archive | ||
* s: srt download | ||
*/ | ||
class Stat extends Document { | ||
constructor () { | ||
super() | ||
this.schema({ | ||
ts: { | ||
type: Number, | ||
default: Stat._getCurrentTs, | ||
}, | ||
type: String, | ||
value: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
}) | ||
} | ||
|
||
/** | ||
* Archive a show | ||
* @param {Boolean} isArchived | ||
*/ | ||
static archive (isArchived) { | ||
this.incrementValue('r', isArchived) | ||
} | ||
|
||
/** | ||
* Add a show | ||
* @param {Boolean} isAdd | ||
*/ | ||
static addShow (isAdd) { | ||
this.incrementValue('a', isAdd) | ||
} | ||
|
||
/** | ||
* Mark View | ||
* @param {Boolean} isView | ||
*/ | ||
static markView (isView) { | ||
this.incrementValue('v', isView) | ||
} | ||
|
||
/** | ||
* Mark DL | ||
* @param {Boolean} isDL | ||
*/ | ||
static markDl (isDL) { | ||
this.incrementValue('d', isDL) | ||
} | ||
|
||
/** | ||
* Increment a stat | ||
* @param {String} type | ||
* @param {Boolean} increment | ||
*/ | ||
static incrementValue (type, increment) { | ||
this.findOne({ | ||
ts: this._getCurrentTs(), | ||
type: type, | ||
}).then((stat) => { | ||
// Create if don't exist | ||
if (!stat) { | ||
stat = Stat.create({ | ||
type: type, | ||
}) | ||
} | ||
|
||
// Increment | ||
if (increment) { | ||
stat.value++ | ||
} else { | ||
stat.value-- | ||
} | ||
|
||
// Save | ||
stat.save() | ||
}) | ||
} | ||
|
||
/** | ||
* Get the current Timestamp | ||
* @return {number} | ||
* @private | ||
*/ | ||
static _getCurrentTs () { | ||
let currentDate = new Date() | ||
currentDate.setHours(0, 0, 0, 0) | ||
|
||
return currentDate.getTime() / 1000 | ||
} | ||
|
||
/** | ||
* Get the collection name | ||
* @return {string} | ||
*/ | ||
static collectionName () { | ||
return 'stats' | ||
} | ||
} | ||
|
||
export default Stat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.