1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-07 21:37:04 +09:00

fix unpacker, update revision

This commit is contained in:
Roman Khafizianov 2025-04-08 18:31:00 +02:00
parent f61f37b8a5
commit d6a0c32e57
No known key found for this signature in database
GPG key ID: F07A7D55A2684852
5 changed files with 78 additions and 71 deletions

View file

@ -62,55 +62,51 @@ type File struct {
func processFile(file File, outputFile string) {
defer file.RC.Close()
content, err := ioutil.ReadAll(file.RC)
if err != nil {
log.Fatalf("Failed to read file: %v", err)
if !strings.HasSuffix(file.Name, ".pb") && !strings.HasPrefix(file.Name, constant.ProfileFile) {
// write file as is
if err := os.MkdirAll(filepath.Dir(outputFile), 0755); err != nil {
log.Fatalf("Failed to create output subdirectory: %v", err)
}
// write from reader to file
outFile, err := os.Create(outputFile)
if err != nil {
log.Fatalf("Failed to create output file: %v", err)
}
defer outFile.Close()
if _, err := io.Copy(outFile, file.RC); err != nil {
log.Fatalf("Failed to copy file: %v", err)
}
return
}
// assuming Snapshot is a protobuf message
var snapshot proto.Message = &pb.ChangeSnapshot{}
if strings.HasPrefix(file.Name, constant.ProfileFile) {
snapshot = &pb.Profile{}
}
if strings.HasSuffix(file.Name, ".json") {
if err := jsonpb.UnmarshalString(string(content), snapshot); err != nil {
log.Fatalf("Failed to parse jsonpb message: %v", err)
}
// convert to pb and write to outputFile
pbData, err := proto.Marshal(snapshot)
if err != nil {
log.Fatalf("Failed to marshal jsonpb message to protobuf: %v", err)
}
outputFile = strings.TrimSuffix(outputFile, filepath.Ext(outputFile)) + ".pb"
if err := ioutil.WriteFile(outputFile, pbData, 0644); err != nil {
log.Fatalf("Failed to write pb file: %v", err)
}
} else {
content, err := ioutil.ReadAll(file.RC)
if err != nil {
log.Fatalf("Failed to read file: %v", err)
}
if err := proto.Unmarshal(content, snapshot); err != nil {
snapshot = &pb.SnapshotWithType{}
if err := proto.Unmarshal(content, snapshot); err != nil {
snapshot = &pb.SnapshotWithType{}
if err := proto.Unmarshal(content, snapshot); err != nil {
log.Fatalf("Failed to parse protobuf message: %v", err)
}
}
// convert to jsonpb and write to outputFile
jsonData, err := jsonM.MarshalToString(snapshot)
if err != nil {
log.Fatalf("Failed to marshal protobuf message to json: %v", err)
}
outputFile = strings.TrimSuffix(outputFile, filepath.Ext(outputFile)) + ".json"
if err := ioutil.WriteFile(outputFile, []byte(jsonData), 0644); err != nil {
log.Fatalf("Failed to write json file: %v", err)
log.Fatalf("Failed to parse protobuf message: %v", err)
}
}
// convert to jsonpb and write to outputFile
jsonData, err := jsonM.MarshalToString(snapshot)
if err != nil {
log.Fatalf("Failed to marshal protobuf message to json: %v", err)
}
outputFile = strings.TrimSuffix(outputFile, filepath.Ext(outputFile)) + ".json"
if err := ioutil.WriteFile(outputFile, []byte(jsonData), 0644); err != nil {
log.Fatalf("Failed to write json file: %v", err)
}
}
func handleZip(input, output string) {
@ -167,7 +163,7 @@ func createZipFromDirectory(input, output string) {
return err
}
if !info.IsDir() && strings.HasSuffix(info.Name(), ".json") {
if !info.IsDir() {
// Get relative path
rel, err := filepath.Rel(input, path)
if err != nil {
@ -178,6 +174,15 @@ func createZipFromDirectory(input, output string) {
if err != nil {
return err
}
if !strings.HasSuffix(info.Name(), ".json") {
// pass original file
fw, err := w.Create(rel)
if err != nil {
return err
}
_, err = fw.Write(data)
return nil
}
isProfile := strings.HasPrefix(info.Name(), constant.ProfileFile)

View file

@ -9,7 +9,7 @@ import (
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
)
const TypeChecksum = "4c26441b1e7a99b4344c736f8237e70b122fd4b0923015c8fcb375dc5804cb55"
const TypeChecksum = "2036a5654c912ee27758ac5c32356c3e1446905db136e7486740858f3ff7e623"
const (
TypePrefix = "_ot"
)
@ -100,7 +100,7 @@ var (
Name: "Chat [deprecated]",
Readonly: true,
RelationLinks: []*model.RelationLink{MustGetRelationLink(RelationKeyTag)},
Revision: 1,
Revision: 2,
Types: []model.SmartBlockType{model.SmartBlockType_ChatObject},
Url: TypePrefix + "chat",
},
@ -170,6 +170,7 @@ var (
PluralName: "Dates",
Readonly: true,
RelationLinks: []*model.RelationLink{MustGetRelationLink(RelationKeyTag)},
Revision: 1,
Types: []model.SmartBlockType{model.SmartBlockType_Date},
Url: TypePrefix + "date",
},

View file

@ -15,7 +15,7 @@
"ingredients",
"time"
],
"revision": 2
"revision": 3
},
{
"id": "note",
@ -31,7 +31,7 @@
"relations": [
"tag"
],
"revision": 2
"revision": 3
},
{
"id": "contact",
@ -50,7 +50,7 @@
"email",
"phone"
],
"revision": 2
"revision": 3
},
{
"id": "bookmark",
@ -68,7 +68,7 @@
"picture",
"source"
],
"revision": 2
"revision": 3
},
{
"id": "date",
@ -83,7 +83,8 @@
"layout": "date",
"relations": [
"tag"
]
],
"revision": 1
},
{
"id": "task",
@ -104,7 +105,7 @@
"linkedProjects",
"status"
],
"revision": 2
"revision": 3
},
{
"id": "relation",
@ -124,7 +125,7 @@
"relationDefaultValue",
"relationFormatObjectTypes"
],
"revision": 2
"revision": 3
},
{
"id": "book",
@ -144,7 +145,7 @@
"status",
"url"
],
"revision": 2
"revision": 3
},
{
"id": "video",
@ -171,7 +172,7 @@
"exposure"
],
"restrictObjectCreation": true,
"revision": 4
"revision": 5
},
{
"id": "dashboard",
@ -201,7 +202,7 @@
"genre",
"status"
],
"revision": 2
"revision": 3
},
{
"id": "objectType",
@ -219,7 +220,7 @@
"recommendedRelations",
"recommendedLayout"
],
"revision": 2
"revision": 3
},
{
"id": "relationOption",
@ -246,7 +247,7 @@
"tag"
],
"restrictObjectCreation": true,
"revision": 2
"revision": 3
},
{
"id": "spaceView",
@ -263,7 +264,7 @@
"tag"
],
"restrictObjectCreation": true,
"revision": 1
"revision": 2
},
{
"id": "participant",
@ -280,7 +281,7 @@
"tag"
],
"restrictObjectCreation": true,
"revision": 3
"revision": 4
},
{
"id": "template",
@ -297,7 +298,7 @@
"targetObjectType",
"templateIsBundled"
],
"revision": 3
"revision": 4
},
{
"id": "set",
@ -314,7 +315,7 @@
"tag",
"setOf"
],
"revision": 3
"revision": 4
},
{
"id": "collection",
@ -330,7 +331,7 @@
"relations": [
"tag"
],
"revision": 2
"revision": 3
},
{
"id": "diaryEntry",
@ -340,14 +341,14 @@
"Page"
],
"iconColor": 2,
"iconName":"reader",
"iconName": "reader",
"hidden": false,
"layout": "basic",
"relations": [
"tag",
"mood"
],
"revision": 2
"revision": 3
},
{
"id": "page",
@ -363,7 +364,7 @@
"relations": [
"tag"
],
"revision": 2
"revision": 3
},
{
"id": "image",
@ -391,7 +392,7 @@
"focalRatio"
],
"restrictObjectCreation": true,
"revision": 4
"revision": 5
},
{
"id": "profile",
@ -408,7 +409,7 @@
"relations": [
"tag"
],
"revision": 2
"revision": 3
},
{
"id": "audio",
@ -435,7 +436,7 @@
"audioLyrics"
],
"restrictObjectCreation": true,
"revision": 4
"revision": 5
},
{
"id": "goal",
@ -455,7 +456,7 @@
"status",
"tasks"
],
"revision": 2
"revision": 3
},
{
"id": "file",
@ -476,7 +477,7 @@
"fileMimeType"
],
"restrictObjectCreation": true,
"revision": 4
"revision": 5
},
{
"id": "project",
@ -493,7 +494,7 @@
"tag",
"tasks"
],
"revision": 2
"revision": 3
},
{
"id": "chat",
@ -506,9 +507,9 @@
"hidden": true,
"layout": "chat",
"relations": [
"tag"
"tag"
],
"revision": 1
"revision": 2
},
{
"id": "chatDerived",
@ -524,6 +525,6 @@
"relations": [
"tag"
],
"revision": 3
"revision": 4
}
]
]

Binary file not shown.