mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-11-10 15:16:20 -06:00
A file import ran inside the upload request. A big export takes minutes, far longer than a reverse proxy holds a request open, so the client got a 502 while the import kept running and kept the user's migration slot, and there was no way to cancel or retry it. The upload request now only validates what is cheap to validate, claims the slot, spools the upload into a per-process temp directory and queues a FileMigrationRequestedEvent. FileMigrationListener runs the import through the lifecycle it now shares with the OAuth migrations: stale event skip, panic recovery, heartbeat, outcome and notifications. The vikunja-file migrator rejects a non-zip or structurally broken export before queueing; ticktick, wekan and csv would have to parse the whole upload, so they fail in the job and report through the status and failure mail. The csv migrator receives its column mapping as options carried with the event.
71 lines
2.8 KiB
Go
71 lines
2.8 KiB
Go
// Vikunja is a to-do list application to facilitate your life.
|
|
// Copyright 2018-present Vikunja and contributors. All rights reserved.
|
|
//
|
|
// 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, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// 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/>.
|
|
|
|
package migration
|
|
|
|
import (
|
|
"io"
|
|
|
|
"code.vikunja.io/api/pkg/user"
|
|
)
|
|
|
|
type MigratorName interface {
|
|
// Name holds the name of the migration.
|
|
// This is used to show the name to users and to keep track of users who already migrated.
|
|
Name() string
|
|
}
|
|
|
|
// Migrator is the basic migrator interface which is shared among all migrators
|
|
type Migrator interface {
|
|
MigratorName
|
|
// Migrate is the interface used to migrate a user's tasks from another platform to vikunja.
|
|
// The user object is the user who's tasks will be migrated.
|
|
Migrate(user *user.User) error
|
|
// AuthURL returns a url for clients to authenticate against.
|
|
// The use case for this are Oauth flows, where the server token should remain hidden and not
|
|
// known to the frontend.
|
|
AuthURL() string
|
|
}
|
|
|
|
// CredentialsChecker is implemented by migrators that authenticate with credentials passed in the
|
|
// migrate request (instead of an OAuth code). The handlers call it before queueing the migration
|
|
// so bad credentials fail the request instead of a background job.
|
|
type CredentialsChecker interface {
|
|
CheckCredentials() error
|
|
}
|
|
|
|
// FileMigrator handles importing Vikunja data from a file. The implementation of it determines the format.
|
|
type FileMigrator interface {
|
|
MigratorName
|
|
// Migrate is the interface used to migrate a user's tasks, project and other things from a file to vikunja.
|
|
// The user object is the user who's tasks will be migrated.
|
|
Migrate(user *user.User, file io.ReaderAt, size int64) error
|
|
}
|
|
|
|
// FileValidator is implemented by file migrators that can cheaply reject a
|
|
// broken upload. Imports run in the background, so without this a user who
|
|
// picked the wrong file gets a "started" response and a failure mail later.
|
|
type FileValidator interface {
|
|
ValidateFile(file io.ReaderAt, size int64) error
|
|
}
|
|
|
|
// FileMigratorOptions is implemented by file migrators that need request
|
|
// parameters beyond the file itself, such as the CSV importer's column mapping.
|
|
// The options are carried to the background job as JSON.
|
|
type FileMigratorOptions interface {
|
|
SetOptions(options []byte) error
|
|
}
|