mirror of
https://codeberg.org/timelimit/timelimit-server.git
synced 2026-08-31 19:03:45 +02:00
Remove saving Apps in the legacy format
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* server component for the TimeLimit App
|
||||
* Copyright (C) 2019 - 2020 Jonas Lochmann
|
||||
* Copyright (C) 2019 - 2022 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
|
||||
@@ -29,26 +29,6 @@ export async function deleteFamilies ({ database, familiyIds }: {
|
||||
}
|
||||
|
||||
await database.transaction(async (transaction) => {
|
||||
// app
|
||||
await database.app.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction
|
||||
})
|
||||
|
||||
// app activity
|
||||
await database.appActivity.destroy({
|
||||
where: {
|
||||
familyId: {
|
||||
[Sequelize.Op.in]: familiyIds
|
||||
}
|
||||
},
|
||||
transaction
|
||||
})
|
||||
|
||||
// category
|
||||
await database.category.destroy({
|
||||
where: {
|
||||
|
||||
@@ -40,23 +40,6 @@ export async function removeDevice ({ database, familyId, deviceId, websocket, t
|
||||
throw new Conflict()
|
||||
}
|
||||
|
||||
// remove app entries
|
||||
await database.app.destroy({
|
||||
where: {
|
||||
familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction
|
||||
})
|
||||
|
||||
await database.appActivity.destroy({
|
||||
where: {
|
||||
familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction
|
||||
})
|
||||
|
||||
// remove as current device
|
||||
await database.user.update({
|
||||
currentDevice: ''
|
||||
|
||||
@@ -15,49 +15,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { AddInstalledAppsAction } from '../../../../action'
|
||||
import { AppAttributes, maxPackageNameLength } from '../../../../database/app'
|
||||
import { Cache } from '../cache'
|
||||
import { ApplyActionException } from '../exception'
|
||||
|
||||
export async function dispatchAddInstalledApps ({ deviceId, action, cache }: {
|
||||
export async function dispatchAddInstalledApps (_: {
|
||||
deviceId: string
|
||||
action: AddInstalledAppsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
action.apps.forEach((app) => {
|
||||
if (app.packageName.length > maxPackageNameLength) {
|
||||
throw new ApplyActionException({
|
||||
staticMessage: 'package name too long',
|
||||
dynamicMessage: 'package name too long: ' + app.packageName
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
await cache.database.app.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
packageName: {
|
||||
[Sequelize.Op.in]: action.apps.map((app) => app.packageName)
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
await cache.database.app.bulkCreate(
|
||||
action.apps.map((app): AppAttributes => ({
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
packageName: app.packageName,
|
||||
title: app.title,
|
||||
isLaunchable: app.isLaunchable,
|
||||
recommendation: app.recommendation
|
||||
})),
|
||||
{ transaction: cache.transaction }
|
||||
)
|
||||
|
||||
cache.devicesWithModifiedInstalledApps.add(deviceId)
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -15,26 +15,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { RemoveInstalledAppsAction } from '../../../../action'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchRemoveInstalledApps ({ deviceId, action, cache }: {
|
||||
export async function dispatchRemoveInstalledApps (_: {
|
||||
deviceId: string
|
||||
action: RemoveInstalledAppsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
await cache.database.app.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
packageName: {
|
||||
[Sequelize.Op.in]: action.packageNames
|
||||
}
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.devicesWithModifiedInstalledApps.add(deviceId)
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -15,85 +15,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { chunk } from 'lodash'
|
||||
import * as Sequelize from 'sequelize'
|
||||
import { UpdateAppActivitiesAction } from '../../../../action'
|
||||
import { AppActivityAttributes, maxActivityNameLength, maxPackageNameLength } from '../../../../database/appactivity'
|
||||
import { Cache } from '../cache'
|
||||
import { ApplyActionException } from '../exception'
|
||||
|
||||
export async function dispatchUpdateAppActivities ({ deviceId, action, cache }: {
|
||||
export async function dispatchUpdateAppActivities (_: {
|
||||
deviceId: string
|
||||
action: UpdateAppActivitiesAction
|
||||
cache: Cache
|
||||
}) {
|
||||
action.updatedOrAdded.forEach((app) => {
|
||||
if (app.packageName.length > maxPackageNameLength) {
|
||||
throw new ApplyActionException({
|
||||
staticMessage: 'package name too long',
|
||||
dynamicMessage: 'package name too long: ' + app.packageName
|
||||
})
|
||||
}
|
||||
|
||||
if (app.activityName.length > maxActivityNameLength) {
|
||||
throw new ApplyActionException({
|
||||
staticMessage: 'activity name too long',
|
||||
dynamicMessage: 'activity name too long: ' + app.activityName
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
if (action.updatedOrAdded.length > 0) {
|
||||
const chuncks = chunk(action.updatedOrAdded, 500)
|
||||
|
||||
for (const items of chuncks) {
|
||||
await cache.database.appActivity.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
[Sequelize.Op.or]: (
|
||||
items.map((item) => ({
|
||||
packageName: item.packageName,
|
||||
activityName: item.activityName
|
||||
}))
|
||||
)
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
|
||||
await cache.database.appActivity.bulkCreate(
|
||||
action.updatedOrAdded.map((item): AppActivityAttributes => ({
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
packageName: item.packageName,
|
||||
activityName: item.activityName,
|
||||
title: item.title
|
||||
})),
|
||||
{ transaction: cache.transaction }
|
||||
)
|
||||
}
|
||||
|
||||
if (action.removed.length > 0) {
|
||||
const chunks = chunk(action.removed, 500)
|
||||
|
||||
for (const items of chunks) {
|
||||
await cache.database.appActivity.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
[Sequelize.Op.or]: (
|
||||
items.map((item) => ({
|
||||
packageName: item.packageName,
|
||||
activityName: item.activityName
|
||||
}))
|
||||
)
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
cache.devicesWithModifiedInstalledApps.add(deviceId)
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -16,44 +16,12 @@
|
||||
*/
|
||||
|
||||
import { UpdateInstalledAppsAction } from '../../../../action'
|
||||
import { types } from '../../../../database/encryptedapplist'
|
||||
import { generateVersionId } from '../../../../util/token'
|
||||
import { Cache } from '../cache'
|
||||
|
||||
export async function dispatchUpdateInstalledApps ({ deviceId, action, cache }: {
|
||||
export async function dispatchUpdateInstalledApps (_: {
|
||||
deviceId: string
|
||||
action: UpdateInstalledAppsAction
|
||||
cache: Cache
|
||||
}) {
|
||||
async function upsert({ type, data }: { type: number, data: Buffer }) {
|
||||
await cache.database.encryptedAppList.upsert({
|
||||
familyId: cache.familyId,
|
||||
deviceId,
|
||||
type,
|
||||
version: generateVersionId(),
|
||||
data
|
||||
}, { transaction: cache.transaction })
|
||||
}
|
||||
|
||||
if (action.base) {
|
||||
await upsert({ type: types.base, data: action.base })
|
||||
}
|
||||
|
||||
if (action.diff) {
|
||||
await upsert({ type: types.diff, data: action.diff })
|
||||
}
|
||||
|
||||
if (action.wipe) {
|
||||
await cache.database.app.destroy({
|
||||
where: {
|
||||
familyId: cache.familyId,
|
||||
deviceId
|
||||
},
|
||||
transaction: cache.transaction
|
||||
})
|
||||
|
||||
cache.devicesWithModifiedInstalledApps.add(deviceId)
|
||||
}
|
||||
|
||||
cache.incrementTriggeredSyncLevel(1)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user