Skip to content

Commit b616db2

Browse files
committed
Allow downloading Folddisco results
1 parent 94a96e8 commit b616db2

4 files changed

Lines changed: 79 additions & 7 deletions

File tree

backend/alignment.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,3 +650,27 @@ func ResultArchive(w io.Writer, id Id, base string) (err error) {
650650
}
651651
return nil
652652
}
653+
654+
func ResultFolddiscoArchive(w io.Writer, id Id, base string, databases []string) (err error) {
655+
gw := gzip.NewWriter(w)
656+
defer func() {
657+
cerr := gw.Close()
658+
if err == nil {
659+
err = cerr
660+
}
661+
}()
662+
tw := tar.NewWriter(gw)
663+
defer func() {
664+
cerr := tw.Close()
665+
if err == nil {
666+
err = cerr
667+
}
668+
}()
669+
670+
for _, name := range databases {
671+
if err = addFile(tw, name+".m8"); err != nil {
672+
return err
673+
}
674+
}
675+
return nil
676+
}

backend/server.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,39 @@ func server(jobsystem JobSystem, config ConfigRoot) {
753753
io.Copy(w, bufio.NewReader(file))
754754
}).Methods("GET")
755755

756+
r.HandleFunc("/result/folddisco/download/{ticket}", func(w http.ResponseWriter, req *http.Request) {
757+
vars := mux.Vars(req)
758+
ticket, err := jobsystem.GetTicket(Id(vars["ticket"]))
759+
if err != nil {
760+
http.Error(w, err.Error(), http.StatusBadRequest)
761+
return
762+
}
763+
764+
status, err := jobsystem.Status(ticket.Id)
765+
if err != nil || status != StatusComplete {
766+
http.Error(w, err.Error(), http.StatusBadRequest)
767+
return
768+
}
769+
770+
name := "folddisco_results_" + string(ticket.Id) + ".tar.gz"
771+
path := filepath.Join(filepath.Clean(config.Paths.Results), string(ticket.Id), name)
772+
if _, err := os.Stat(path); os.IsNotExist(err) {
773+
http.Error(w, err.Error(), http.StatusBadRequest)
774+
return
775+
}
776+
file, err := os.Open(path)
777+
if err != nil {
778+
http.Error(w, err.Error(), http.StatusBadRequest)
779+
return
780+
}
781+
defer file.Close()
782+
783+
w.Header().Set("Content-Disposition", "attachment; filename=\""+name+"\"")
784+
w.Header().Set("Content-Type", "application/octet-stream")
785+
w.Header().Set("Cache-Control", "public, max-age=3600")
786+
io.Copy(w, bufio.NewReader(file))
787+
}).Methods("GET")
788+
756789
r.HandleFunc("/result/foldmason/{ticket}", func(w http.ResponseWriter, req *http.Request) {
757790
vars := mux.Vars(req)
758791
ticket, err := jobsystem.GetTicket(Id(vars["ticket"]))

backend/worker.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,21 @@ printf("%c%c%c%c",5,0,0,0) > db".dbtype"; printf("%c%c%c%c",0,0,0,0) > db"_seq.d
16041604
}
16051605
}
16061606

1607+
path := filepath.Join(filepath.Clean(config.Paths.Results), string(request.Id))
1608+
file, err := os.Create(filepath.Join(path, "folddisco_results_"+string(request.Id)+".tar.gz"))
1609+
if err != nil {
1610+
return &JobExecutionError{err}
1611+
}
1612+
err = ResultFolddiscoArchive(file, request.Id, path, job.Database)
1613+
if err != nil {
1614+
file.Close()
1615+
return &JobExecutionError{err}
1616+
}
1617+
err = file.Close()
1618+
if err != nil {
1619+
return &JobExecutionError{err}
1620+
}
1621+
16071622
if config.Verbose {
16081623
log.Print("Process finished gracefully without error")
16091624
}

frontend/Navigation.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
</v-list-item>
114114
</template>
115115
</v-list-group>
116-
<!-- <v-list-group v-else-if="$route.name === 'folddiscoresult'" v-model="expanded">
116+
<v-list-group v-else-if="$route.name === 'folddiscoresult'" v-model="expanded">
117117
<template slot="activator">
118118
<v-list-item-action>
119119
<v-icon>{{ $MDI.FileDownloadOutline }}</v-icon>
@@ -125,19 +125,19 @@
125125
<template v-if="!this.mini">
126126
<v-list-item
127127
@click="$ELECTRON ? electronDownload($route.params.ticket) : null"
128-
:href="$ELECTRON ? null : url('api/result/download/' + $route.params.ticket)"
128+
:href="$ELECTRON ? null : url('api/result/folddisco/download/' + $route.params.ticket)"
129129
:target="$ELECTRON ? null : '_blank'"
130130
title="TODO"
131131
>
132132
<v-list-item-action>
133133
<v-icon>{{ $ELECTRON ? $MDI.FileDownloadOutline : $MDI.TableLarge }}</v-icon>
134134
</v-list-item-action>
135135
<v-list-item-content>
136-
<v-list-item-title>TODO</v-list-item-title>
137-
<v-list-item-subtitle>TODO</v-list-item-subtitle>
136+
<v-list-item-title>Hit tables</v-list-item-title>
137+
<v-list-item-subtitle>Archive of M8 files</v-list-item-subtitle>
138138
</v-list-item-content>
139139
</v-list-item>
140-
<v-list-item
140+
<!-- <v-list-item
141141
@click="downloadJSON"
142142
style="padding-left: 16px;"
143143
title="Download all result data (JSON file)"
@@ -149,9 +149,9 @@
149149
<v-list-item-title>All data</v-list-item-title>
150150
<v-list-item-subtitle>Reloadable JSON file</v-list-item-subtitle>
151151
</v-list-item-content>
152-
</v-list-item>
152+
</v-list-item> -->
153153
</template>
154-
</v-list-group> -->
154+
</v-list-group>
155155

156156
<v-divider></v-divider>
157157

0 commit comments

Comments
 (0)