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:
@@ -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