(w http.ResponseWriter, r *http.Request)
| 897 | } |
| 898 | |
| 899 | func (s *Server) uploadAsset(w http.ResponseWriter, r *http.Request) { |
| 900 | cfg := s.currentConfig() |
| 901 | r.Body = http.MaxBytesReader(w, r.Body, cfg.MaxAssetBytes+multipartOverheadBytes) |
| 902 | if err := r.ParseMultipartForm(8 << 20); err != nil { |
| 903 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 904 | return |
| 905 | } |
| 906 | notePath := r.FormValue("notePath") |
| 907 | file, header, err := r.FormFile("file") |
| 908 | if err != nil { |
| 909 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 910 | return |
| 911 | } |
| 912 | defer file.Close() |
| 913 | asset, err := s.currentVault().ImportAsset(notePath, header.Filename, file) |
| 914 | if err != nil { |
| 915 | if errors.Is(err, vault.ErrAssetTooLarge) { |
| 916 | http.Error(w, "asset too large", http.StatusRequestEntityTooLarge) |
| 917 | return |
| 918 | } |
| 919 | writeError(w, err) |
| 920 | return |
| 921 | } |
| 922 | writeJSON(w, http.StatusOK, asset) |
| 923 | } |
| 924 | |
| 925 | // --- WebSocket watcher --- |
| 926 |
nothing calls this directly
no test coverage detected