main

mattermost/focalboard

Last updated at: 29/12/2023 09:46

import_export.go

TLDR

This file, import_export.go, contains definitions for various types and functions related to the import and export of data in the Demo Projects project.

Classes

Archive

The Archive class represents an import/export archive. It contains a version number, a date, and a list of Block objects.

ArchiveHeader

The ArchiveHeader class represents the content of the first file (version.json) within an archive. It contains a version number and a date.

ArchiveLine

The ArchiveLine class represents any line in an archive. It has a type and raw JSON data.

ErrUnsupportedArchiveVersion

The ErrUnsupportedArchiveVersion class is an error returned when trying to import an archive with a version that the server does not support. It contains the unsupported version number.

ErrUnsupportedArchiveLineType

The ErrUnsupportedArchiveLineType class is an error returned when trying to import an archive containing an unsupported line type. It contains the unsupported line number and type.

Methods

None

package model

import (
	"encoding/json"
	"errors"
	"fmt"
)

var (
	ErrInvalidImageBlock = errors.New("invalid image block")
)

// Archive is an import / export archive.
// TODO: remove once default templates are converted to new archive format.
type Archive struct {
	Version int64   `json:"version"`
	Date    int64   `json:"date"`
	Blocks  []Block `json:"blocks"`
}

// ArchiveHeader is the content of the first file (`version.json`) within an archive.
type ArchiveHeader struct {
	Version int   `json:"version"`
	Date    int64 `json:"date"`
}

// ArchiveLine is any line in an archive.
type ArchiveLine struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

// ExportArchiveOptions provides options when exporting one or more boards
// to an archive.
type ExportArchiveOptions struct {
	TeamID string

	// BoardIDs is the list of boards to include in the archive.
	// Empty slice means export all boards from workspace/team.
	BoardIDs []string
}

// ImportArchiveOptions provides options when importing an archive.
type ImportArchiveOptions struct {
	TeamID        string
	ModifiedBy    string
	BoardModifier BoardModifier
	BlockModifier BlockModifier
}

// ErrUnsupportedArchiveVersion is an error returned when trying to import an
// archive with a version that this server does not support.
type ErrUnsupportedArchiveVersion struct {
	got  int
	want int
}

// NewErrUnsupportedArchiveVersion creates a ErrUnsupportedArchiveVersion error.
func NewErrUnsupportedArchiveVersion(got int, want int) ErrUnsupportedArchiveVersion {
	return ErrUnsupportedArchiveVersion{
		got:  got,
		want: want,
	}
}

func (e ErrUnsupportedArchiveVersion) Error() string {
	return fmt.Sprintf("unsupported archive version; got %d, want %d", e.got, e.want)
}

// ErrUnsupportedArchiveLineType is an error returned when trying to import an
// archive containing an unsupported line type.
type ErrUnsupportedArchiveLineType struct {
	line int
	got  string
}

// NewErrUnsupportedArchiveLineType creates a ErrUnsupportedArchiveLineType error.
func NewErrUnsupportedArchiveLineType(line int, got string) ErrUnsupportedArchiveLineType {
	return ErrUnsupportedArchiveLineType{
		line: line,
		got:  got,
	}
}

func (e ErrUnsupportedArchiveLineType) Error() string {
	return fmt.Sprintf("unsupported archive line type; got %s, line %d", e.got, e.line)
}