mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Compare commits
21
Commits
2026-03-30
...
2026-08-04
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7df7790288 | ||
|
|
1aee08f409 | ||
|
|
85cd9f3bb0 | ||
|
|
52bde0bc23 | ||
|
|
1e5e74659e | ||
|
|
893f3664cf | ||
|
|
ccfbf97d36 | ||
|
|
bf338f4aff | ||
|
|
91cb44d244 | ||
|
|
235115168f | ||
|
|
b2bcc3715f | ||
|
|
2f35b969bf | ||
|
|
48d6a061f8 | ||
|
|
0b6ece0d28 | ||
|
|
271b27ffe9 | ||
|
|
b80b74b072 | ||
|
|
190ae54602 | ||
|
|
eb87d331b3 | ||
|
|
5a6f37e4c7 | ||
|
|
bd4b5b206b | ||
|
|
a8db1ec1a9 |
+1
-1
@@ -5,7 +5,7 @@ RUN mkdir -p /usr/src/app
|
|||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Install app dependencies
|
# Install app dependencies
|
||||||
COPY package.json package-lock.json tsconfig.json .eslintignore .eslintrc.js Readme.md /usr/src/app/
|
COPY package.json package-lock.json tsconfig.json eslint.config.mjs Readme.md /usr/src/app/
|
||||||
COPY src/ /usr/src/app/src/
|
COPY src/ /usr/src/app/src/
|
||||||
COPY scripts/ /usr/src/app/scripts/
|
COPY scripts/ /usr/src/app/scripts/
|
||||||
COPY other/ /usr/src/app/other/
|
COPY other/ /usr/src/app/other/
|
||||||
|
|||||||
+5
-1
@@ -100,7 +100,10 @@ request properties: ``purchaseToken``, ``purchaseId`` and ``dryRun``
|
|||||||
|
|
||||||
- ``purchasetoken`` is a string which the client shows at the purchase screen
|
- ``purchasetoken`` is a string which the client shows at the purchase screen
|
||||||
- ``purchaseId`` is the ID that is used at the bill
|
- ``purchaseId`` is the ID that is used at the bill
|
||||||
- ``dryRun`` is a boolean; setting true will skip the actual unlocking
|
- ``dryRun`` is a boolean
|
||||||
|
- setting true will skip the actual unlocking
|
||||||
|
- false will add a four week tolerance to the token expiry to permit checking now and unlocking later
|
||||||
|
- ``type`` is a string and must be ``year``, ``month`` or ``unpaid14``
|
||||||
|
|
||||||
### response
|
### response
|
||||||
|
|
||||||
@@ -121,6 +124,7 @@ The response contains the following properties:
|
|||||||
- optional object
|
- optional object
|
||||||
- should be shown to the support
|
- should be shown to the support
|
||||||
- ``wasAlreadyExecuted`` (boolean, set if and only if ``ok`` is true)
|
- ``wasAlreadyExecuted`` (boolean, set if and only if ``ok`` is true)
|
||||||
|
- ``mail`` (string, set if and only if ``ok`` is true)
|
||||||
|
|
||||||
If the request was malformed: HTTP status code 400 Bad Request
|
If the request was malformed: HTTP status code 400 Bad Request
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ Use this before a purchase to check if a purchase is possible.
|
|||||||
|
|
||||||
see [this JSON schema](../schema/candopurchaserequest.md)
|
see [this JSON schema](../schema/candopurchaserequest.md)
|
||||||
|
|
||||||
|
Note that ``type`` is not used at all.
|
||||||
|
|
||||||
### response
|
### response
|
||||||
|
|
||||||
On a invalid request body: HTTP status code 400 Bad request
|
On a invalid request body: HTTP status code 400 Bad request
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": [
|
"required": [
|
||||||
"deviceAuthToken",
|
"deviceAuthToken"
|
||||||
"type"
|
|
||||||
],
|
],
|
||||||
"definitions": {},
|
"definitions": {},
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ https://timelimit.io/CanDoPurchaseRequest
|
|||||||
|
|
||||||
| Property | Type | Required | Nullable | Defined by |
|
| Property | Type | Required | Nullable | Defined by |
|
||||||
| :---------------------------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| :---------------------------------- | :------- | :------- | :------------- | :------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [type](#type) | `string` | Required | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-type.md "https://timelimit.io/CanDoPurchaseRequest#/properties/type") |
|
| [type](#type) | `string` | Optional | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-type.md "https://timelimit.io/CanDoPurchaseRequest#/properties/type") |
|
||||||
| [deviceAuthToken](#deviceauthtoken) | `string` | Required | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-deviceauthtoken.md "https://timelimit.io/CanDoPurchaseRequest#/properties/deviceAuthToken") |
|
| [deviceAuthToken](#deviceauthtoken) | `string` | Required | cannot be null | [CanDoPurchaseRequest](candopurchaserequest-properties-deviceauthtoken.md "https://timelimit.io/CanDoPurchaseRequest#/properties/deviceAuthToken") |
|
||||||
|
|
||||||
## type
|
## type
|
||||||
@@ -27,7 +27,7 @@ https://timelimit.io/CanDoPurchaseRequest
|
|||||||
|
|
||||||
`type`
|
`type`
|
||||||
|
|
||||||
* is required
|
* is optional
|
||||||
|
|
||||||
* Type: `string`
|
* Type: `string`
|
||||||
|
|
||||||
|
|||||||
Generated
+294
-510
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -55,7 +55,7 @@
|
|||||||
"jose": "^4.9.3",
|
"jose": "^4.9.3",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"mariadb": "^2.5.2",
|
"mariadb": "^2.5.2",
|
||||||
"nodemailer": "^8.0.4",
|
"nodemailer": "^9.0.4",
|
||||||
"pg": "^8.5.1",
|
"pg": "^8.5.1",
|
||||||
"pg-hstore": "^2.3.3",
|
"pg-hstore": "^2.3.3",
|
||||||
"rate-limiter-flexible": "^2.1.15",
|
"rate-limiter-flexible": "^2.1.15",
|
||||||
|
|||||||
+14
-5
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -141,7 +141,8 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
|||||||
typeof req.body !== 'object' ||
|
typeof req.body !== 'object' ||
|
||||||
typeof req.body.purchaseToken !== 'string' ||
|
typeof req.body.purchaseToken !== 'string' ||
|
||||||
typeof req.body.purchaseId !== 'string' ||
|
typeof req.body.purchaseId !== 'string' ||
|
||||||
typeof req.body.dryRun !== 'boolean'
|
typeof req.body.dryRun !== 'boolean' ||
|
||||||
|
typeof req.body.type !== 'string'
|
||||||
) {
|
) {
|
||||||
throw new BadRequest()
|
throw new BadRequest()
|
||||||
}
|
}
|
||||||
@@ -149,8 +150,13 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
|||||||
const purchaseToken: string = req.body.purchaseToken
|
const purchaseToken: string = req.body.purchaseToken
|
||||||
const purchaseId: string = req.body.purchaseId
|
const purchaseId: string = req.body.purchaseId
|
||||||
const dryRun: boolean = req.body.dryRun
|
const dryRun: boolean = req.body.dryRun
|
||||||
|
const type: string = req.body.type
|
||||||
|
|
||||||
const tokenContent = await verifyIdentitifyToken(purchaseToken)
|
if (type !== 'month' && type !== 'year' && type !== 'unpaid14') {
|
||||||
|
throw new BadRequest()
|
||||||
|
}
|
||||||
|
|
||||||
|
const tokenContent = await verifyIdentitifyToken(purchaseToken, dryRun)
|
||||||
|
|
||||||
if (tokenContent.purpose !== 'purchase') {
|
if (tokenContent.purpose !== 'purchase') {
|
||||||
res.json({ ok: false, error: 'token invalid', detail: 'wrong purpose' })
|
res.json({ ok: false, error: 'token invalid', detail: 'wrong purpose' })
|
||||||
@@ -228,7 +234,10 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
|||||||
error: 'family not found'
|
error: 'family not found'
|
||||||
}
|
}
|
||||||
|
|
||||||
const canDoPurchase = canDoNextPurchase({ fullVersionUntil: parseInt(familyEntry.fullVersionUntil) })
|
const canDoPurchase = canDoNextPurchase({
|
||||||
|
fullVersionUntil: parseInt(familyEntry.fullVersionUntil),
|
||||||
|
fullVersionDebts: parseInt(familyEntry.fullVersionDebts),
|
||||||
|
})
|
||||||
|
|
||||||
if (!canDoPurchase) {
|
if (!canDoPurchase) {
|
||||||
const lastPurchase = await database.purchase.findOne({
|
const lastPurchase = await database.purchase.findOne({
|
||||||
@@ -256,7 +265,7 @@ export const createAdminRouter = ({ database, websocket, eventHandler }: {
|
|||||||
await addPurchase({
|
await addPurchase({
|
||||||
database,
|
database,
|
||||||
familyId: tokenContent.familyId,
|
familyId: tokenContent.familyId,
|
||||||
type: 'year',
|
type,
|
||||||
service: 'directpurchase',
|
service: 'directpurchase',
|
||||||
transactionId: purchaseId,
|
transactionId: purchaseId,
|
||||||
websocket,
|
websocket,
|
||||||
|
|||||||
+10
-7
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -37,16 +37,16 @@ export const createPurchaseRouter = ({ database, websocket }: {
|
|||||||
const router = Router()
|
const router = Router()
|
||||||
|
|
||||||
router.post('/can-do-purchase', json(), async (req, res, next) => {
|
router.post('/can-do-purchase', json(), async (req, res, next) => {
|
||||||
if (!areGooglePlayPaymentsPossible) {
|
|
||||||
res.json({ canDoPurchase: 'no because not supported by the server' })
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!isCanDoPurchaseRequest(req.body)) {
|
if (!isCanDoPurchaseRequest(req.body)) {
|
||||||
throw new BadRequest()
|
throw new BadRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.body.type === 'googleplay' && !areGooglePlayPaymentsPossible) {
|
||||||
|
res.json({ canDoPurchase: 'no because not supported by the server' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const result: boolean = await database.transaction(async (transaction) => {
|
const result: boolean = await database.transaction(async (transaction) => {
|
||||||
const familyEntry = await requireFamilyEntry({
|
const familyEntry = await requireFamilyEntry({
|
||||||
database,
|
database,
|
||||||
@@ -54,7 +54,10 @@ export const createPurchaseRouter = ({ database, websocket }: {
|
|||||||
transaction
|
transaction
|
||||||
})
|
})
|
||||||
|
|
||||||
return canDoNextPurchase({ fullVersionUntil: parseInt(familyEntry.fullVersionUntil, 10) })
|
return canDoNextPurchase({
|
||||||
|
fullVersionUntil: parseInt(familyEntry.fullVersionUntil, 10),
|
||||||
|
fullVersionDebts: parseInt(familyEntry.fullVersionDebts, 10),
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
+1
-1
@@ -113,7 +113,7 @@ export interface CreateRegisterDeviceTokenRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CanDoPurchaseRequest {
|
export interface CanDoPurchaseRequest {
|
||||||
type: 'googleplay' | 'any'
|
type?: 'googleplay' | 'any'
|
||||||
deviceAuthToken: string
|
deviceAuthToken: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3353,8 +3353,7 @@ export const isCanDoPurchaseRequest: (value: unknown) => value is CanDoPurchaseR
|
|||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": [
|
"required": [
|
||||||
"deviceAuthToken",
|
"deviceAuthToken"
|
||||||
"type"
|
|
||||||
],
|
],
|
||||||
"definitions": definitions,
|
"definitions": definitions,
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#"
|
"$schema": "http://json-schema.org/draft-07/schema#"
|
||||||
|
|||||||
+20
-3
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -37,8 +37,13 @@ export interface FamilyAttributesVersion3 {
|
|||||||
u2fKeysVersion: string
|
u2fKeysVersion: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FamilyAttributesVersion4 {
|
||||||
|
fullVersionDebts: string
|
||||||
|
}
|
||||||
|
|
||||||
export type FamilyAttributes = FamilyAttributesVersion1 &
|
export type FamilyAttributes = FamilyAttributesVersion1 &
|
||||||
FamilyAttributesVersion2 & FamilyAttributesVersion3
|
FamilyAttributesVersion2 & FamilyAttributesVersion3 &
|
||||||
|
FamilyAttributesVersion4
|
||||||
|
|
||||||
export type FamilyModel = Sequelize.Model<FamilyAttributes> & FamilyAttributes
|
export type FamilyModel = Sequelize.Model<FamilyAttributes> & FamilyAttributes
|
||||||
export type FamilyModelStatic = typeof Sequelize.Model & {
|
export type FamilyModelStatic = typeof Sequelize.Model & {
|
||||||
@@ -76,10 +81,22 @@ export const attributesVersion3: SequelizeAttributes<FamilyAttributesVersion3> =
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const attributesVersion4: SequelizeAttributes<FamilyAttributesVersion4> = {
|
||||||
|
fullVersionDebts: {
|
||||||
|
type: Sequelize.BIGINT,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
validate: {
|
||||||
|
min: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const attributes: SequelizeAttributes<FamilyAttributes> = {
|
export const attributes: SequelizeAttributes<FamilyAttributes> = {
|
||||||
...attributesVersion1,
|
...attributesVersion1,
|
||||||
...attributesVersion2,
|
...attributesVersion2,
|
||||||
...attributesVersion3
|
...attributesVersion3,
|
||||||
|
...attributesVersion4
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createFamilyModel = (sequelize: Sequelize.Sequelize): FamilyModelStatic => sequelize.define('Family', attributes) as FamilyModelStatic
|
export const createFamilyModel = (sequelize: Sequelize.Sequelize): FamilyModelStatic => sequelize.define('Family', attributes) as FamilyModelStatic
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* server component for the TimeLimit App
|
||||||
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { QueryInterface, Sequelize, Transaction } from 'sequelize'
|
||||||
|
import { attributesVersion4 as familyAttributes } from '../../family'
|
||||||
|
|
||||||
|
export async function up (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||||
|
await sequelize.transaction({
|
||||||
|
type: Transaction.TYPES.EXCLUSIVE
|
||||||
|
}, async (transaction) => {
|
||||||
|
await queryInterface.addColumn('Families', 'fullVersionDebts', {
|
||||||
|
...familyAttributes.fullVersionDebts
|
||||||
|
}, {
|
||||||
|
transaction
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down (queryInterface: QueryInterface, sequelize: Sequelize) {
|
||||||
|
await sequelize.transaction({
|
||||||
|
type: Transaction.TYPES.EXCLUSIVE
|
||||||
|
}, async (transaction) => {
|
||||||
|
await queryInterface.removeColumn('Families', 'fullVersionDebts', { transaction })
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -23,7 +23,7 @@ export interface PurchaseAttributes {
|
|||||||
familyId: string
|
familyId: string
|
||||||
service: 'googleplay' | 'directpurchase'
|
service: 'googleplay' | 'directpurchase'
|
||||||
transactionId: string
|
transactionId: string
|
||||||
type: 'month' | 'year'
|
type: 'month' | 'year' | 'unpaid14'
|
||||||
loggedAt: string
|
loggedAt: string
|
||||||
previousFullVersionEndTime: string
|
previousFullVersionEndTime: string
|
||||||
newFullVersionEndTime: string
|
newFullVersionEndTime: string
|
||||||
@@ -44,7 +44,7 @@ export const attributes: SequelizeAttributes<PurchaseAttributes> = {
|
|||||||
type: Sequelize.STRING,
|
type: Sequelize.STRING,
|
||||||
primaryKey: true
|
primaryKey: true
|
||||||
},
|
},
|
||||||
type: createEnumColumn(['month', 'year']),
|
type: createEnumColumn(['month', 'year', 'unpaid14']),
|
||||||
loggedAt: { ...timestampColumn },
|
loggedAt: { ...timestampColumn },
|
||||||
previousFullVersionEndTime: { ...timestampColumn },
|
previousFullVersionEndTime: { ...timestampColumn },
|
||||||
newFullVersionEndTime: { ...timestampColumn }
|
newFullVersionEndTime: { ...timestampColumn }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -82,7 +82,8 @@ export async function createFamily ({
|
|||||||
fullVersionUntil: (Date.now() + 1000 * 60 * 60 * 24 * 14).toString(10),
|
fullVersionUntil: (Date.now() + 1000 * 60 * 60 * 24 * 14).toString(10),
|
||||||
hasFullVersion: true,
|
hasFullVersion: true,
|
||||||
nextServerKeyRequestSeq: '1',
|
nextServerKeyRequestSeq: '1',
|
||||||
u2fKeysVersion: generateVersionId()
|
u2fKeysVersion: generateVersionId(),
|
||||||
|
fullVersionDebts: '0'
|
||||||
}, { transaction })
|
}, { transaction })
|
||||||
|
|
||||||
// create parent user
|
// create parent user
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -21,13 +21,14 @@ import { notifyClientsAboutChangesDelayed } from '../../function/websocket'
|
|||||||
import { WebsocketApi } from '../../websocket'
|
import { WebsocketApi } from '../../websocket'
|
||||||
|
|
||||||
const day = 1000 * 60 * 60 * 24
|
const day = 1000 * 60 * 60 * 24
|
||||||
|
const week = day * 7
|
||||||
const month = day * 31
|
const month = day * 31
|
||||||
const year = day * 366
|
const year = day * 366
|
||||||
|
|
||||||
export const addPurchase = async ({ database, familyId, type, service, transactionId, websocket, transaction }: {
|
export const addPurchase = async ({ database, familyId, type, service, transactionId, websocket, transaction }: {
|
||||||
database: Database
|
database: Database
|
||||||
familyId: string
|
familyId: string
|
||||||
type: 'month' | 'year'
|
type: 'month' | 'year' | 'unpaid14'
|
||||||
service: 'googleplay' | 'directpurchase'
|
service: 'googleplay' | 'directpurchase'
|
||||||
transactionId: string
|
transactionId: string
|
||||||
websocket: WebsocketApi
|
websocket: WebsocketApi
|
||||||
@@ -57,11 +58,42 @@ export const addPurchase = async ({ database, familyId, type, service, transacti
|
|||||||
}
|
}
|
||||||
|
|
||||||
const previousFullVersionEndTime = familyEntry.fullVersionUntil
|
const previousFullVersionEndTime = familyEntry.fullVersionUntil
|
||||||
|
const previousFullVersionDebts = parseInt(familyEntry.fullVersionDebts, 10)
|
||||||
|
|
||||||
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + (type === 'year' ? year : month)
|
if (type === 'month' || type === 'year') {
|
||||||
|
const typeDuration = type === 'year' ? year : month
|
||||||
|
|
||||||
familyEntry.fullVersionUntil = newFullVersionUntil.toString(10)
|
if (typeDuration > previousFullVersionDebts) {
|
||||||
familyEntry.hasFullVersion = true
|
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + typeDuration - previousFullVersionDebts
|
||||||
|
|
||||||
|
familyEntry.fullVersionUntil = newFullVersionUntil.toString(10)
|
||||||
|
familyEntry.fullVersionDebts = '0'
|
||||||
|
familyEntry.hasFullVersion = true
|
||||||
|
} else {
|
||||||
|
familyEntry.fullVersionDebts = (previousFullVersionDebts - typeDuration).toString(10)
|
||||||
|
}
|
||||||
|
} else if (type === 'unpaid14') {
|
||||||
|
const debtsAdd = 2 * week
|
||||||
|
const debtsMax = 3 * week
|
||||||
|
|
||||||
|
const newDebts = Math.min(debtsMax, previousFullVersionDebts + debtsAdd)
|
||||||
|
|
||||||
|
if (newDebts <= previousFullVersionDebts) {
|
||||||
|
// do not save anything
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const durationToAdd = newDebts - previousFullVersionDebts
|
||||||
|
|
||||||
|
const newFullVersionUntil = Math.max(parseInt(familyEntry.fullVersionUntil, 10), Date.now()) + durationToAdd
|
||||||
|
|
||||||
|
familyEntry.fullVersionUntil = newFullVersionUntil.toString(10)
|
||||||
|
familyEntry.fullVersionDebts = newDebts.toString(10)
|
||||||
|
familyEntry.hasFullVersion = true
|
||||||
|
} else {
|
||||||
|
throw new Error()
|
||||||
|
}
|
||||||
|
|
||||||
await familyEntry.save({ transaction })
|
await familyEntry.save({ transaction })
|
||||||
|
|
||||||
@@ -72,7 +104,7 @@ export const addPurchase = async ({ database, familyId, type, service, transacti
|
|||||||
type,
|
type,
|
||||||
loggedAt: Date.now().toString(10),
|
loggedAt: Date.now().toString(10),
|
||||||
previousFullVersionEndTime,
|
previousFullVersionEndTime,
|
||||||
newFullVersionEndTime: newFullVersionUntil.toString(10)
|
newFullVersionEndTime: familyEntry.fullVersionUntil
|
||||||
}, {
|
}, {
|
||||||
transaction
|
transaction
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -15,6 +15,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const canDoNextPurchase = ({ fullVersionUntil }: {fullVersionUntil: number}) => (
|
export const canDoNextPurchase = ({ fullVersionUntil, fullVersionDebts }: {
|
||||||
fullVersionUntil < (Date.now() + 1000 * 60 * 60 * 24 * 31) // 31 days
|
fullVersionUntil: number
|
||||||
|
fullVersionDebts: number
|
||||||
|
}) => (
|
||||||
|
(fullVersionUntil - fullVersionDebts) < (Date.now() + 1000 * 60 * 60 * 24 * 31) // 31 days
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -43,7 +43,7 @@ export const requireFamilyEntry = async ({ database, deviceAuthToken, transactio
|
|||||||
where: {
|
where: {
|
||||||
familyId: deviceEntry.familyId
|
familyId: deviceEntry.familyId
|
||||||
},
|
},
|
||||||
attributes: ['fullVersionUntil'],
|
attributes: ['fullVersionUntil', 'fullVersionDebts'],
|
||||||
transaction
|
transaction
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -52,7 +52,8 @@ export const requireFamilyEntry = async ({ database, deviceAuthToken, transactio
|
|||||||
}
|
}
|
||||||
|
|
||||||
const familyEntry = {
|
const familyEntry = {
|
||||||
fullVersionUntil: familyEntryUnsafe.fullVersionUntil
|
fullVersionUntil: familyEntryUnsafe.fullVersionUntil,
|
||||||
|
fullVersionDebts: familyEntryUnsafe.fullVersionDebts,
|
||||||
}
|
}
|
||||||
|
|
||||||
return familyEntry
|
return familyEntry
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2024 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -67,6 +67,9 @@ export async function dispatchUpdateTimelimitRule ({
|
|||||||
const wasSessionDurationLimitationEnabled =
|
const wasSessionDurationLimitationEnabled =
|
||||||
ruleEntry.sessionPauseMilliseconds > 0 && ruleEntry.sessionDurationMilliseconds > 0
|
ruleEntry.sessionPauseMilliseconds > 0 && ruleEntry.sessionDurationMilliseconds > 0
|
||||||
|
|
||||||
|
const isSessionDurationLimitationEnabled =
|
||||||
|
action.sessionPauseMilliseconds > 0 && action.sessionDurationMilliseconds > 0
|
||||||
|
|
||||||
const countOldAffectedDays = Array(7)
|
const countOldAffectedDays = Array(7)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
.reduce((sum, _, index) => sum + ((ruleEntry.dayMaskAsBitmask >> index) & 1), 0)
|
.reduce((sum, _, index) => sum + ((ruleEntry.dayMaskAsBitmask >> index) & 1), 0)
|
||||||
@@ -78,6 +81,7 @@ export async function dispatchUpdateTimelimitRule ({
|
|||||||
action.start <= ruleEntry.startMinuteOfDay &&
|
action.start <= ruleEntry.startMinuteOfDay &&
|
||||||
action.end >= ruleEntry.endMinuteOfDay &&
|
action.end >= ruleEntry.endMinuteOfDay &&
|
||||||
(!wasSessionDurationLimitationEnabled || (
|
(!wasSessionDurationLimitationEnabled || (
|
||||||
|
isSessionDurationLimitationEnabled &&
|
||||||
action.sessionDurationMilliseconds <= ruleEntry.sessionDurationMilliseconds &&
|
action.sessionDurationMilliseconds <= ruleEntry.sessionDurationMilliseconds &&
|
||||||
action.sessionPauseMilliseconds >= ruleEntry.sessionPauseMilliseconds
|
action.sessionPauseMilliseconds >= ruleEntry.sessionPauseMilliseconds
|
||||||
)) &&
|
)) &&
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* server component for the TimeLimit App
|
||||||
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, version 3 of the License.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createHash } from 'crypto'
|
||||||
|
|
||||||
|
const updateMessage =
|
||||||
|
'Please update the TimeLimit App to the latest release. ' +
|
||||||
|
'In your current version, synchronization and purchases may not work as expected.' +
|
||||||
|
'\n\n' +
|
||||||
|
'Bitte die TimeLimit-App aktualisieren. ' +
|
||||||
|
'Mit der momentan installierten Version kann es zu Einschränkungen bei der Synchronisation und bei Käufen kommen.'
|
||||||
|
|
||||||
|
export function getCampaign({ familyId, isClient750OrNewer }: {
|
||||||
|
familyId: string
|
||||||
|
isClient750OrNewer: boolean
|
||||||
|
}): string | undefined {
|
||||||
|
const now = Date.now()
|
||||||
|
|
||||||
|
const campaigns = [
|
||||||
|
{
|
||||||
|
enable: !isClient750OrNewer,
|
||||||
|
seed: 'Q05NwM4nyUfiYg6K', // require('crypto').randomBytes(12).toString('base64')
|
||||||
|
startTime: 1784160000000, // new Date('2026-07-16').valueOf()
|
||||||
|
endTime: 1785369600000, // new Date('2026-07-30').valueOf()
|
||||||
|
startPercentage: 0,
|
||||||
|
endPercentage: 10,
|
||||||
|
message: updateMessage,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const campaign of campaigns) {
|
||||||
|
if (!campaign.enable) continue
|
||||||
|
if (now < campaign.startTime) continue
|
||||||
|
|
||||||
|
const progress = Math.min((now - campaign.startTime) / (campaign.endTime - campaign.startTime), 1)
|
||||||
|
const chanceInPercent = campaign.startPercentage + progress * (campaign.endPercentage - campaign.startPercentage)
|
||||||
|
|
||||||
|
const hasher = createHash('SHA3-224')
|
||||||
|
|
||||||
|
hasher.update(campaign.seed, 'base64')
|
||||||
|
hasher.update(familyId)
|
||||||
|
|
||||||
|
const hash = hasher.digest().readUInt32BE(0)
|
||||||
|
const match = hash < chanceInPercent * Math.pow(2, 32) / 100
|
||||||
|
|
||||||
|
if (match) return campaign.message
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import { getStatusMessage } from '../../../function/statusmessage'
|
|||||||
import { ClientDataStatus } from '../../../object/clientdatastatus'
|
import { ClientDataStatus } from '../../../object/clientdatastatus'
|
||||||
import { ServerDataStatus } from '../../../object/serverdatastatus'
|
import { ServerDataStatus } from '../../../object/serverdatastatus'
|
||||||
import { EventHandler } from '../../../monitoring/eventhandler'
|
import { EventHandler } from '../../../monitoring/eventhandler'
|
||||||
|
import { getCampaign } from './campaign'
|
||||||
import {
|
import {
|
||||||
getCategoryAssignedApps, getCategoryBaseDatas, getCategoryDataToSync,
|
getCategoryAssignedApps, getCategoryBaseDatas, getCategoryDataToSync,
|
||||||
getRules, getTasks, getUsedTimes
|
getRules, getTasks, getUsedTimes
|
||||||
@@ -54,12 +55,18 @@ export const generateServerDataStatus = async ({
|
|||||||
const doesClientSupportDh = clientLevel >= 5
|
const doesClientSupportDh = clientLevel >= 5
|
||||||
const doesClientSupportU2f = clientLevel >= 6
|
const doesClientSupportU2f = clientLevel >= 6
|
||||||
const doesClientSupportPing = clientLevel >= 7
|
const doesClientSupportPing = clientLevel >= 7
|
||||||
|
const isClient750OrNewer = clientLevel >= 8 // first release in the post gplay time
|
||||||
|
|
||||||
|
const message: string | undefined =
|
||||||
|
await getStatusMessage({ database, transaction }) ||
|
||||||
|
getCampaign({ familyId, isClient750OrNewer }) ||
|
||||||
|
undefined
|
||||||
|
|
||||||
const result: ServerDataStatus = {
|
const result: ServerDataStatus = {
|
||||||
fullVersion: config.alwaysPro ? 1 : (
|
fullVersion: config.alwaysPro ? 1 : (
|
||||||
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
|
familyEntry.hasFullVersion ? parseInt(familyEntry.fullVersionUntil, 10) : 0
|
||||||
),
|
),
|
||||||
message: await getStatusMessage({ database, transaction }) || undefined,
|
message,
|
||||||
apiLevel: 9
|
apiLevel: 9
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* server component for the TimeLimit App
|
* server component for the TimeLimit App
|
||||||
* Copyright (C) 2019 - 2022 Jonas Lochmann
|
* Copyright (C) 2019 - 2026 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Affero General Public License as
|
* it under the terms of the GNU Affero General Public License as
|
||||||
@@ -33,12 +33,15 @@ export async function createIdentityToken({ purpose, familyId, userId, mail }: I
|
|||||||
.join('\n')
|
.join('\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function verifyIdentitifyToken(token: string): Promise<IdentityTokenPayload> {
|
export async function verifyIdentitifyToken(token: string, dryRun: boolean): Promise<IdentityTokenPayload> {
|
||||||
try {
|
try {
|
||||||
const { payload } = await jwtVerify(
|
const { payload } = await jwtVerify(
|
||||||
Buffer.from(token, 'base64').toString('ascii'),
|
Buffer.from(token, 'base64').toString('ascii'),
|
||||||
getSignSecret(),
|
getSignSecret(),
|
||||||
{ algorithms: ['HS512'] }
|
{
|
||||||
|
algorithms: ['HS512'],
|
||||||
|
clockTolerance: dryRun ? 0 : '4w',
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!isIdentityTokenPayload(payload)) throw new BadPayloadException()
|
if (!isIdentityTokenPayload(payload)) throw new BadPayloadException()
|
||||||
|
|||||||
Reference in New Issue
Block a user