mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
export type AppRecommendation = 'whitelist' | 'blacklist' | 'none'
|
||||
export const appRecommendationValues: Array<AppRecommendation> = ['whitelist', 'blacklist', 'none']
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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 { AppRecommendation } from './apprecommendation'
|
||||
|
||||
export class InstalledApp {
|
||||
readonly packageName: string
|
||||
readonly title: string
|
||||
readonly isLaunchable: boolean
|
||||
readonly recommendation: AppRecommendation
|
||||
|
||||
constructor ({ packageName, title, isLaunchable, recommendation }: {packageName: string, title: string, isLaunchable: boolean, recommendation: AppRecommendation}) {
|
||||
this.packageName = packageName
|
||||
this.title = title
|
||||
this.isLaunchable = isLaunchable
|
||||
this.recommendation = recommendation
|
||||
}
|
||||
|
||||
serialize = (): SerializedInstalledApp => ({
|
||||
packageName: this.packageName,
|
||||
title: this.title,
|
||||
isLaunchable: this.isLaunchable,
|
||||
recommendation: this.recommendation
|
||||
})
|
||||
|
||||
static parse = ({ packageName, title, isLaunchable, recommendation }: SerializedInstalledApp) => (
|
||||
new InstalledApp({ packageName, title, isLaunchable, recommendation })
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedInstalledApp {
|
||||
packageName: string
|
||||
title: string
|
||||
isLaunchable: boolean
|
||||
recommendation: AppRecommendation
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
export type NewPermissionStatus = 'not granted' | 'not supported' | 'granted'
|
||||
export const newPermissionStatusValues: Array<NewPermissionStatus> = ['not granted', 'not supported', 'granted']
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
export type ProtectionLevel = 'none' | 'simple device admin' | 'password device admin' | 'device owner'
|
||||
export const protetionLevels: Array<ProtectionLevel> = ['none', 'simple device admin', 'password device admin', 'device owner']
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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/>.
|
||||
*/
|
||||
|
||||
export type RuntimePermissionStatus = 'not granted' | 'not required' | 'granted'
|
||||
export const runtimePermissionStatusValues: Array<RuntimePermissionStatus> = ['not granted', 'not required', 'granted']
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 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 { assertIdWithinFamily } from '../util/token'
|
||||
|
||||
export class TimelimitRule {
|
||||
readonly ruleId: string
|
||||
readonly categoryId: string
|
||||
readonly maxTimeInMillis: number
|
||||
readonly dayMask: number // stored as bitmask
|
||||
readonly applyToExtraTimeUsage: boolean
|
||||
|
||||
constructor ({ ruleId, categoryId, maxTimeInMillis, dayMask, applyToExtraTimeUsage }: {
|
||||
ruleId: string
|
||||
categoryId: string
|
||||
maxTimeInMillis: number
|
||||
dayMask: number
|
||||
applyToExtraTimeUsage: boolean
|
||||
}) {
|
||||
this.ruleId = ruleId
|
||||
this.categoryId = categoryId
|
||||
this.maxTimeInMillis = maxTimeInMillis
|
||||
this.dayMask = dayMask
|
||||
this.applyToExtraTimeUsage = applyToExtraTimeUsage
|
||||
|
||||
assertIdWithinFamily(ruleId)
|
||||
assertIdWithinFamily(categoryId)
|
||||
|
||||
if (maxTimeInMillis < 0 || (!Number.isSafeInteger(maxTimeInMillis))) {
|
||||
throw new Error('maxTimeInMillis must be >= 0')
|
||||
}
|
||||
|
||||
if (!(
|
||||
Number.isSafeInteger(dayMask) ||
|
||||
dayMask < 0 ||
|
||||
dayMask > (1 | 2 | 4 | 8 | 16 | 32 | 64)
|
||||
)) {
|
||||
throw new Error('invalid day mask')
|
||||
}
|
||||
}
|
||||
|
||||
serialize = (): SerializedTimeLimitRule => ({
|
||||
ruleId: this.ruleId,
|
||||
categoryId: this.categoryId,
|
||||
time: this.maxTimeInMillis,
|
||||
days: this.dayMask,
|
||||
extraTime: this.applyToExtraTimeUsage
|
||||
})
|
||||
|
||||
static parse = ({ ruleId, categoryId, time, days, extraTime }: SerializedTimeLimitRule) => (
|
||||
new TimelimitRule({
|
||||
ruleId,
|
||||
categoryId,
|
||||
maxTimeInMillis: time,
|
||||
dayMask: days,
|
||||
applyToExtraTimeUsage: extraTime
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export interface SerializedTimeLimitRule {
|
||||
ruleId: string
|
||||
categoryId: string
|
||||
time: number
|
||||
days: number
|
||||
extraTime: boolean
|
||||
}
|
||||
Reference in New Issue
Block a user