2011-06-09 22:00:20 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-10-18 18:12:01 +00:00
|
|
|
package server
|
2011-06-09 22:00:20 +00:00
|
|
|
|
|
|
|
import (
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"io"
|
|
|
|
"net/http"
|
2011-06-09 22:00:20 +00:00
|
|
|
|
2013-02-12 04:33:53 +00:00
|
|
|
"camlistore.org/pkg/blobref"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/httputil"
|
|
|
|
"camlistore.org/pkg/schema"
|
2011-06-09 22:00:20 +00:00
|
|
|
)
|
|
|
|
|
2013-02-12 04:33:53 +00:00
|
|
|
// uploadHelperResponse is the response from serveUploadHelper.
|
|
|
|
type uploadHelperResponse struct {
|
|
|
|
Got []*uploadHelperGotItem `json:"got"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type uploadHelperGotItem struct {
|
|
|
|
FileName string `json:"filename"`
|
|
|
|
FormName string `json:"formname"`
|
|
|
|
FileRef *blobref.BlobRef `json:"fileref"`
|
|
|
|
}
|
2011-06-09 22:00:20 +00:00
|
|
|
|
2013-02-12 04:33:53 +00:00
|
|
|
func (ui *UIHandler) serveUploadHelper(rw http.ResponseWriter, req *http.Request) {
|
2012-11-07 17:57:43 +00:00
|
|
|
if ui.root.Storage == nil {
|
2013-02-12 04:33:53 +00:00
|
|
|
httputil.ServeJSONError(rw, httputil.ServerError("No BlobRoot configured"))
|
2011-06-09 22:00:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
mr, err := req.MultipartReader()
|
|
|
|
if err != nil {
|
2013-02-12 04:33:53 +00:00
|
|
|
httputil.ServeJSONError(rw, httputil.ServerError("reading body: " + err.Error()))
|
2011-06-09 22:00:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2013-02-12 04:33:53 +00:00
|
|
|
var got []*uploadHelperGotItem
|
2011-06-09 22:00:20 +00:00
|
|
|
for {
|
|
|
|
part, err := mr.NextPart()
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
if err == io.EOF {
|
2011-06-09 22:00:20 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if err != nil {
|
2013-02-12 04:33:53 +00:00
|
|
|
httputil.ServeJSONError(rw, httputil.ServerError("reading body: " + err.Error()))
|
2011-06-09 22:00:20 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
fileName := part.FileName()
|
|
|
|
if fileName == "" {
|
|
|
|
continue
|
|
|
|
}
|
2012-11-07 17:57:43 +00:00
|
|
|
br, err := schema.WriteFileFromReader(ui.root.Storage, fileName, part)
|
2013-02-12 04:33:53 +00:00
|
|
|
if err != nil {
|
|
|
|
httputil.ServeJSONError(rw, httputil.ServerError("writing to blobserver: " + err.Error()))
|
2011-06-09 22:00:20 +00:00
|
|
|
return
|
|
|
|
}
|
2013-02-12 04:33:53 +00:00
|
|
|
got = append(got, &uploadHelperGotItem{
|
|
|
|
FileName: part.FileName(),
|
|
|
|
FormName: part.FormName(),
|
|
|
|
FileRef: br,
|
|
|
|
})
|
2011-06-09 22:00:20 +00:00
|
|
|
}
|
2013-02-12 04:33:53 +00:00
|
|
|
|
|
|
|
httputil.ReturnJSON(rw, &uploadHelperResponse{Got: got})
|
2011-06-09 22:00:20 +00:00
|
|
|
}
|