Compare commits
8 commits
develop
...
import-zip
Author | SHA1 | Date | |
---|---|---|---|
|
98700fc576 | ||
|
746f1c7b73 | ||
|
dc2be18d60 | ||
|
54d82eb01f | ||
|
5e4d5ba0ee | ||
|
ac253cab85 | ||
|
63fdc6a225 | ||
|
4063c2c7bf |
6 changed files with 220 additions and 8 deletions
21
account.go
21
account.go
|
@ -13,6 +13,13 @@ package writefreely
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/guregu/null/zero"
|
||||
|
@ -22,12 +29,6 @@ import (
|
|||
"github.com/writeas/web-core/log"
|
||||
"github.com/writeas/writefreely/author"
|
||||
"github.com/writeas/writefreely/page"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -655,6 +656,14 @@ func viewExportFull(app *app, w http.ResponseWriter, r *http.Request) ([]byte, s
|
|||
return data, filename, err
|
||||
}
|
||||
|
||||
func viewImportOptions(app *app, u *User, w http.ResponseWriter, r *http.Request) error {
|
||||
// Fetch extra user data
|
||||
p := NewUserPage(app, r, u, "Import", nil)
|
||||
|
||||
showUserPage(w, "import", p)
|
||||
return nil
|
||||
}
|
||||
|
||||
func viewMeAPI(app *app, w http.ResponseWriter, r *http.Request) error {
|
||||
reqJSON := IsJSON(r.Header.Get("Content-Type"))
|
||||
uObj := struct {
|
||||
|
|
119
import.go
Normal file
119
import.go
Normal file
|
@ -0,0 +1,119 @@
|
|||
package writefreely
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
type importUser struct {
|
||||
Username string `json:"username"`
|
||||
HasPass bool `json:"has_pass"`
|
||||
Email string `json:"email"`
|
||||
Created string `json:"created"`
|
||||
Collections []importCollection `json:"collections"`
|
||||
}
|
||||
|
||||
type importCollection struct {
|
||||
Alias string `json:"alias"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
StyleSheet string `json:"style_sheet"`
|
||||
Public bool `json:"public"`
|
||||
Views int `json:"views"`
|
||||
URL string `json:"url"`
|
||||
Total int `json:"total_posts"`
|
||||
Posts []importPost `json:"posts"`
|
||||
}
|
||||
|
||||
type importPost struct {
|
||||
ID string `json:"id"`
|
||||
Slug string `json:"slug"`
|
||||
Appearance string `json:"appearance"`
|
||||
Language string `json:"language"`
|
||||
Rtl bool `json:"rtl"`
|
||||
Created string `json:"created"`
|
||||
Updated string `json:"updated"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Tags []string `json:"tags"`
|
||||
Views int `json:"views"`
|
||||
}
|
||||
|
||||
func jsonReader() {
|
||||
// Open the jsonFile
|
||||
jsonFile, err := os.Open("skye-201905250022.json")
|
||||
// If os.Open returns an error then handle it
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fmt.Println("Successfully Opened users.json")
|
||||
// Defer the closing of our jsonFile so it can be parsed later
|
||||
defer jsonFile.Close()
|
||||
|
||||
// Read the opened xmlFile as a byte array.
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
// Initialize the collections array
|
||||
var u importUser
|
||||
|
||||
// Unmarshal the byteArray which contains the
|
||||
// jsonFile's content into 'importUser'
|
||||
json.Unmarshal(byteValue, &u)
|
||||
|
||||
fmt.Printf("Top level data is: %+v", u)
|
||||
fmt.Println("Collection data is: ")
|
||||
for _, c := range u.Collections {
|
||||
fmt.Println(c)
|
||||
}
|
||||
fmt.Println("Posts data are: ")
|
||||
for _, coll := range u.Collections {
|
||||
for _, p := range coll.Posts {
|
||||
fmt.Println(p)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
// for _, p := range u.Collections[0].Posts {
|
||||
// fmt.Println(p.ID)
|
||||
// }
|
||||
|
||||
// we iterate through every user within our users array and
|
||||
// print out the user Type, their name, and their facebook url
|
||||
// as just an example
|
||||
// for i := 0; i < len(users.Users); i++ {
|
||||
// fmt.Println("User Type: " + users.Users[i].Type)
|
||||
// fmt.Println("User Age: " + strconv.Itoa(users.Users[i].Age))
|
||||
// fmt.Println("User Name: " + users.Users[i].Name)
|
||||
// fmt.Println("Facebook Url: " + users.Users[i].Social.Facebook)
|
||||
// }
|
||||
}
|
||||
|
||||
// func zipreader(src string) ([]string, error) {
|
||||
|
||||
// // Open a zip archive for reading.
|
||||
// r, err := zip.OpenReader("testdata/readme.zip")
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// defer r.Close()
|
||||
|
||||
// // Iterate through the files in the archive,
|
||||
// // printing some of their contents.
|
||||
// for _, f := range r.File {
|
||||
// fmt.Printf("Contents of %s:\n", f.Name)
|
||||
// rc, err := f.Open()
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// _, err = io.CopyN(os.Stdout, rc, 68)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// rc.Close()
|
||||
// fmt.Println()
|
||||
// }
|
||||
|
||||
// return
|
||||
// }
|
|
@ -566,6 +566,26 @@ p {
|
|||
}
|
||||
}
|
||||
|
||||
.formContainer {
|
||||
// border-radius: 10px 10px 10px 10px;
|
||||
// -moz-border-radius: 10px 10px 10px 10px;
|
||||
// -webkit-border-radius: 10px 10px 10px 10px;
|
||||
border-top: 1px solid #ccc;
|
||||
margin-bottom: 2em;
|
||||
padding: 1em 0em 0.5em 1em;
|
||||
}
|
||||
|
||||
.import {
|
||||
& input {
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
& input.fileInput {
|
||||
padding-left: 0;
|
||||
width: 70%;
|
||||
}
|
||||
}
|
||||
|
||||
table.classy {
|
||||
width: 95%;
|
||||
border-collapse: collapse;
|
||||
|
|
|
@ -11,13 +11,14 @@
|
|||
package writefreely
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/writeas/go-webfinger"
|
||||
"github.com/writeas/web-core/log"
|
||||
"github.com/writeas/writefreely/config"
|
||||
"github.com/writefreely/go-nodeinfo"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datastore) {
|
||||
|
@ -78,6 +79,7 @@ func initRoutes(handler *Handler, r *mux.Router, cfg *config.Config, db *datasto
|
|||
me.HandleFunc("/posts/export.json", handler.Download(viewExportPosts, UserLevelUser)).Methods("GET")
|
||||
me.HandleFunc("/export", handler.User(viewExportOptions)).Methods("GET")
|
||||
me.HandleFunc("/export.json", handler.Download(viewExportFull, UserLevelUser)).Methods("GET")
|
||||
me.HandleFunc("/import", handler.User(viewImportOptions)).Methods("GET")
|
||||
me.HandleFunc("/settings", handler.User(viewSettings)).Methods("GET")
|
||||
me.HandleFunc("/invites", handler.User(handleViewUserInvites)).Methods("GET")
|
||||
me.HandleFunc("/logout", handler.Web(viewLogout, UserLevelNone)).Methods("GET")
|
||||
|
|
60
templates/user/import.tmpl
Normal file
60
templates/user/import.tmpl
Normal file
|
@ -0,0 +1,60 @@
|
|||
{{define "import"}}
|
||||
{{template "header" .}}
|
||||
|
||||
<div class="snug content-container">
|
||||
<h2 id="posts-header">Import</h2>
|
||||
<p>You may import your data from another instance here. Please choose the same option for import as you did for export.</p>
|
||||
<div class="formContainer">
|
||||
<form id="importPosts" class="import">
|
||||
<h3>Posts</h3>
|
||||
<p>csv</p>
|
||||
<input class="fileInput" type="file" accept="text/csv"/>
|
||||
<br />
|
||||
<input type="submit" value="Import" />
|
||||
<br />
|
||||
<p>txt</p>
|
||||
<input class="fileInput" type="file" accept="text/txt"/>
|
||||
<br />
|
||||
<input type="submit" value="Import" />
|
||||
</form>
|
||||
</div>
|
||||
<div class="formContainer">
|
||||
<form id="importAll" class="import">
|
||||
<h3>User + Blogs + Posts</h3>
|
||||
<p>json/Prettified</p>
|
||||
<input class="fileInput" type="file" accept="text/JSON"/>
|
||||
<br />
|
||||
<input type="submit" value="Import" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- <div class="snug content-container">
|
||||
<h2 id="posts-header">Import</h2>
|
||||
<p>You may import your data from another instance here.</p>
|
||||
|
||||
<table class="classy export">
|
||||
<tr>
|
||||
<th style="width: 40%">Import</th>
|
||||
<th colspan="2">Format</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Posts</th>
|
||||
<td><p class="text-cta"><a href="">CSV</a></p></td>
|
||||
<td><p class="text-cta"><a href="">TXT</a></p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>User + Blogs + Posts</th>
|
||||
<div>
|
||||
<td><input type="file" accept="text/JSON"/></td>
|
||||
</div>
|
||||
<td><p class="text-cta"><a href="">JSON</a></p></td>
|
||||
<td><p class="text-cta"><a href="">Prettified</a></p></td>
|
||||
</tr>
|
||||
</table>
|
||||
<input type="submit">
|
||||
|
||||
</div> -->
|
||||
|
||||
{{template "footer" .}}
|
||||
{{end}}
|
|
@ -27,6 +27,7 @@
|
|||
{{if .IsAdmin}}<li><a href="/admin">Admin</a></li>{{end}}
|
||||
<li><a href="/me/settings">Settings</a></li>
|
||||
<li><a href="/me/export">Export</a></li>
|
||||
<li><a href="/me/import">Import</a></li>
|
||||
<li class="separator"><hr /></li>
|
||||
<li><a href="/me/logout">Log out</a></li>
|
||||
</ul></li>
|
||||
|
@ -45,6 +46,7 @@
|
|||
{{if .IsAdmin}}<li><a href="/admin">Admin dashboard</a></li>{{end}}
|
||||
<li><a href="/me/settings">Account settings</a></li>
|
||||
<li><a href="/me/export">Export</a></li>
|
||||
<li><a href="/me/import">Import</a></li>
|
||||
{{if .CanInvite}}<li><a href="/me/invites">Invite people</a></li>{{end}}
|
||||
<li class="separator"><hr /></li>
|
||||
<li><a href="/me/logout">Log out</a></li>
|
||||
|
|
Loading…
Add table
Reference in a new issue