mirror of
https://github.com/nkanaev/yarr.git
synced 2025-05-24 00:33:14 +00:00
opml file import/export handlers
This commit is contained in:
parent
a203792b1d
commit
6753a113ad
@ -8,11 +8,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"log"
|
"log"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"mime"
|
"mime"
|
||||||
"strings"
|
"strings"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"math"
|
"math"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
func IndexHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
@ -348,3 +350,29 @@ func SettingsHandler(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OPMLImportHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
if req.Method == "POST" {
|
||||||
|
file, _, err := req.FormFile("opml")
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
content, err := ioutil.ReadAll(file)
|
||||||
|
if err != nil {
|
||||||
|
log.Print(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(string(content))
|
||||||
|
} else {
|
||||||
|
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func OPMLExportHandler(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
if req.Method == "GET" {
|
||||||
|
rw.Header().Set("Content-Type", "application/xml; charset=utf-8")
|
||||||
|
rw.Header().Set("Content-Disposition", `attachment; filename="subscriptions.opml"`)
|
||||||
|
rw.Write([]byte("content"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -79,6 +79,8 @@ var routes []Route = []Route{
|
|||||||
p("/api/items", ItemListHandler),
|
p("/api/items", ItemListHandler),
|
||||||
p("/api/items/:id", ItemHandler),
|
p("/api/items/:id", ItemHandler),
|
||||||
p("/api/settings", SettingsHandler),
|
p("/api/settings", SettingsHandler),
|
||||||
|
p("/opml/import", OPMLImportHandler),
|
||||||
|
p("/opml/export", OPMLExportHandler),
|
||||||
}
|
}
|
||||||
|
|
||||||
func Vars(req *http.Request) map[string]string {
|
func Vars(req *http.Request) map[string]string {
|
||||||
|
@ -228,6 +228,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="settings=='import'">
|
<div v-else-if="settings=='import'">
|
||||||
|
<form id="opml-import-form" enctype="multipart/form-data">
|
||||||
|
<label for="opml-import">Import Subscription</label>
|
||||||
|
<div class="custom-file">
|
||||||
|
<input type="file" class="custom-file-input" id="opml-import" @change="importOPML" name="opml">
|
||||||
|
<label class="custom-file-label" for="opml-import">Choose file</label>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<label class="mt-3">Export Subscriptions</label>
|
||||||
|
<br>
|
||||||
|
<a class="btn btn-default" href="/opml/export" target="_blank">Download</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -74,5 +74,11 @@
|
|||||||
return api('put', '/api/settings', data)
|
return api('put', '/api/settings', data)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
upload_opml: function(form) {
|
||||||
|
return fetch('/opml/import', {
|
||||||
|
method: 'post',
|
||||||
|
body: new FormData(form),
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
@ -240,5 +240,9 @@ var vm = new Vue({
|
|||||||
}
|
}
|
||||||
api.items.update(item.id, {status: item.status})
|
api.items.update(item.id, {status: item.status})
|
||||||
},
|
},
|
||||||
|
importOPML: function(event) {
|
||||||
|
var form = document.querySelector('#opml-import-form')
|
||||||
|
api.upload_opml(form)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user