chore: remove commented code
This commit is contained in:
parent
f0d7a337db
commit
7f5847f7da
198
api/s5/http.go
198
api/s5/http.go
|
@ -510,204 +510,6 @@ func (h *HttpHandler) accountPin(jc jape.Context) {
|
|||
jc.ResponseWriter.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
/*func (h *HttpHandler) directoryUpload(jc jape.Context) {
|
||||
var tryFiles []string
|
||||
var errorPages map[int]string
|
||||
var name string
|
||||
|
||||
if jc.DecodeForm("tryFiles", &tryFiles) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if jc.DecodeForm("errorPages", &errorPages) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if jc.DecodeForm("name", &name) != nil {
|
||||
return
|
||||
}
|
||||
|
||||
r := jc.Request
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
user := middleware.GetUserFromContext(jc.Request.Context())
|
||||
|
||||
errored := func(err error) {
|
||||
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
|
||||
h.logger.Error(errUploadingFile, zap.Error(err))
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(contentType, "multipart/form-data") {
|
||||
_ = jc.Error(errNotMultiformErr, http.StatusBadRequest)
|
||||
h.logger.Error(errorNotMultiform)
|
||||
return
|
||||
}
|
||||
|
||||
err := r.ParseMultipartForm(h.config.GetInt64("core.post-upload-limit"))
|
||||
|
||||
if jc.Check(errMultiformParse, err) != nil {
|
||||
h.logger.Error(errMultiformParse, zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
uploadMap := make(map[string]models.Upload, len(r.MultipartForm.File))
|
||||
mimeMap := make(map[string]string, len(r.MultipartForm.File))
|
||||
|
||||
for _, files := range r.MultipartForm.File {
|
||||
for _, fileHeader := range files {
|
||||
// Open the file.
|
||||
file, err := fileHeader.Open()
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
defer func(file multipart.File) {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
h.logger.Error(errClosingStream, zap.Error(err))
|
||||
}
|
||||
}(file)
|
||||
|
||||
var rs io.ReadSeeker
|
||||
|
||||
hash, err := h.storage.GetHashSmall(rs)
|
||||
_, err = rs.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
|
||||
h.logger.Error(errUploadingFile, zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
if exists, upload := h.storage.FileExists(hash.Hash); exists {
|
||||
uploadMap[fileHeader.Filename] = upload
|
||||
continue
|
||||
}
|
||||
|
||||
hash, err = h.storage.PutFileSmall(rs, "s5")
|
||||
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = rs.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
var mimeBytes [512]byte
|
||||
|
||||
if _, err := file.Read(mimeBytes[:]); err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
mimeType := http.DetectContentType(mimeBytes[:])
|
||||
|
||||
upload, err := h.storage.CreateUpload(hash.Hash, mimeType, user, jc.Request.RemoteAddr, uint64(fileHeader.Size), "s5")
|
||||
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Reset the read pointer back to the start of the file.
|
||||
if _, err := file.Seek(0, io.SeekStart); err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Read a snippet of the file to determine its MIME type.
|
||||
buffer := make([]byte, 512) // 512 bytes should be enough for http.DetectContentType to determine the type
|
||||
if _, err := file.Read(buffer); err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
uploadMap[fileHeader.Filename] = *upload
|
||||
mimeMap[fileHeader.Filename] = mimeType
|
||||
}
|
||||
}
|
||||
filesMap := make(map[string]metadata.WebAppMetadataFileReference, len(uploadMap))
|
||||
|
||||
for name, file := range uploadMap {
|
||||
hashDecoded, err := hex.DecodeString(file.Hash)
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
cid, err := encoding.CIDFromHash(hashDecoded, file.Size, types.CIDTypeRaw, types.HashTypeBlake3)
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
filesMap[name] = *metadata.NewWebAppMetadataFileReference(cid, mimeMap[name])
|
||||
}
|
||||
|
||||
app := metadata.NewWebAppMetadata(name, tryFiles, *metadata.NewExtraMetadata(map[int]interface{}{}), errorPages, filesMap)
|
||||
|
||||
appData, err := msgpack.Marshal(app)
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
var rs = bytes.NewReader(appData)
|
||||
|
||||
hash, err := h.storage.GetHashSmall(rs)
|
||||
_, err = rs.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
|
||||
h.logger.Error(errUploadingFile, zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
if exists, upload := h.storage.FileExists(hash.Hash); exists {
|
||||
cid, err := encoding.CIDFromHash(hash, upload.Size, types.CIDTypeMetadataWebapp, types.HashTypeBlake3)
|
||||
if err != nil {
|
||||
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
|
||||
h.logger.Error(errUploadingFile, zap.Error(err))
|
||||
return
|
||||
}
|
||||
cidStr, err := cid.ToString()
|
||||
if err != nil {
|
||||
_ = jc.Error(errUploadingFileErr, http.StatusInternalServerError)
|
||||
h.logger.Error(errUploadingFile, zap.Error(err))
|
||||
return
|
||||
}
|
||||
jc.Encode(map[string]string{"hash": cidStr})
|
||||
return
|
||||
}
|
||||
|
||||
hash, err = h.storage.PutFileSmall(rs, "s5")
|
||||
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
cid, err := encoding.CIDFromHash(hash, uint64(len(appData)), types.CIDTypeRaw, types.HashTypeBlake3)
|
||||
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
cidStr, err := cid.ToString()
|
||||
if err != nil {
|
||||
errored(err)
|
||||
return
|
||||
}
|
||||
|
||||
jc.Encode(&AppUploadResponse{CID: cidStr})
|
||||
}
|
||||
*/
|
||||
|
||||
func (h *HttpHandler) directoryUpload(jc jape.Context) {
|
||||
// Decode form fields
|
||||
var (
|
||||
|
|
Loading…
Reference in New Issue