chore: fixes to paste ui
This commit is contained in:
		
							parent
							
								
									9a26239aa7
								
							
						
					
					
						commit
						717ed45ffd
					
				@ -1,13 +1,13 @@
 | 
			
		||||
{
 | 
			
		||||
  "files": {
 | 
			
		||||
    "main.css": "/ui/static/css/main.d4025777.css",
 | 
			
		||||
    "main.js": "/ui/static/js/main.1d06557a.js",
 | 
			
		||||
    "main.js": "/ui/static/js/main.939bead5.js",
 | 
			
		||||
    "index.html": "/ui/index.html",
 | 
			
		||||
    "main.d4025777.css.map": "/ui/static/css/main.d4025777.css.map",
 | 
			
		||||
    "main.1d06557a.js.map": "/ui/static/js/main.1d06557a.js.map"
 | 
			
		||||
    "main.939bead5.js.map": "/ui/static/js/main.939bead5.js.map"
 | 
			
		||||
  },
 | 
			
		||||
  "entrypoints": [
 | 
			
		||||
    "static/css/main.d4025777.css",
 | 
			
		||||
    "static/js/main.1d06557a.js"
 | 
			
		||||
    "static/js/main.939bead5.js"
 | 
			
		||||
  ]
 | 
			
		||||
}
 | 
			
		||||
@ -1 +1 @@
 | 
			
		||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/ui/manifest.json"><link rel="shortcut icon" href="/ui/favicon.ico"><title>DN42 Paste</title><script defer="defer" src="/ui/static/js/main.1d06557a.js"></script><link href="/ui/static/css/main.d4025777.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
 | 
			
		||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/ui/manifest.json"><link rel="shortcut icon" href="/ui/favicon.ico"><title>DN42 Paste</title><script defer="defer" src="/ui/static/js/main.939bead5.js"></script><link href="/ui/static/css/main.d4025777.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -200,17 +200,17 @@ class Paste extends Component {
 | 
			
		||||
  onSubmit(event) {
 | 
			
		||||
    event.preventDefault();
 | 
			
		||||
    const { plain } = this.state;
 | 
			
		||||
    const { history } = this.props;
 | 
			
		||||
    // const { history } = this.props;
 | 
			
		||||
 | 
			
		||||
    this.encrypt(plain).then(([hash, decryptKey]) => { history.push('/#/' + hash + '!' + decryptKey) });
 | 
			
		||||
    this.encrypt(plain).then(([hash, decryptKey]) => { history.pushState({}, '', '/ui/#/' + hash + '!' + decryptKey) });
 | 
			
		||||
  }
 | 
			
		||||
  onNew(event) {
 | 
			
		||||
    const { history } = this.props;
 | 
			
		||||
    this.setState({cipher:"", plain:"", hash: "", decryptKey: "", syntax: "text", expire: 604800, burn: false}, () => history.push('/'));
 | 
			
		||||
    // const { history } = this.props;
 | 
			
		||||
    this.setState({cipher:"", plain:"", hash: "", decryptKey: "", syntax: "text", expire: 604800, burn: false}, () => history.pushState({}, '', '/ui'));
 | 
			
		||||
  }
 | 
			
		||||
  onCopy(event) {
 | 
			
		||||
    const { history } = this.props;
 | 
			
		||||
    this.setState({hash: "", decryptKey: ""}, () => history.push('/'))
 | 
			
		||||
    // const { history } = this.props;
 | 
			
		||||
    this.setState({hash: "", decryptKey: ""}, () => history.pushState({}, '', '/ui'))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  decrypt(tx) {
 | 
			
		||||
 | 
			
		||||
@ -71,8 +71,10 @@ func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
				w.WriteHeader(http.StatusBadRequest)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
			dec := base64.NewDecoder(base64.StdEncoding, fd)
 | 
			
		||||
			fd = io.NopCloser(dec)
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
		length := 0
 | 
			
		||||
		if h := r.Header.Get("Content-Length"); h != "" {
 | 
			
		||||
			if i, err := strconv.Atoi(h); err != nil {
 | 
			
		||||
@ -80,34 +82,39 @@ func (a *image) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		id, err := a.put(ctx, w, fd, length)
 | 
			
		||||
		switch {
 | 
			
		||||
		case errors.Is(err, ErrGone):
 | 
			
		||||
			w.WriteHeader(http.StatusGone)
 | 
			
		||||
		case errors.Is(err, ErrNotFound):
 | 
			
		||||
			w.WriteHeader(http.StatusNotFound)
 | 
			
		||||
		case errors.Is(err, ErrReadingContent):
 | 
			
		||||
			w.WriteHeader(http.StatusInternalServerError)
 | 
			
		||||
		case errors.Is(err, ErrUnsupportedType):
 | 
			
		||||
			w.WriteHeader(http.StatusUnsupportedMediaType)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			switch {
 | 
			
		||||
			case errors.Is(err, ErrGone):
 | 
			
		||||
				w.WriteHeader(http.StatusGone)
 | 
			
		||||
			case errors.Is(err, ErrNotFound):
 | 
			
		||||
				w.WriteHeader(http.StatusNotFound)
 | 
			
		||||
			case errors.Is(err, ErrReadingContent):
 | 
			
		||||
				w.WriteHeader(http.StatusInternalServerError)
 | 
			
		||||
			case errors.Is(err, ErrUnsupportedType):
 | 
			
		||||
				w.WriteHeader(http.StatusUnsupportedMediaType)
 | 
			
		||||
			}
 | 
			
		||||
			span.RecordError(err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		type data struct{
 | 
			
		||||
			Link string `json:"link"`
 | 
			
		||||
		type data struct {
 | 
			
		||||
			Link       string `json:"link"`
 | 
			
		||||
			DeleteHash string `json:"deletehash"`
 | 
			
		||||
		}
 | 
			
		||||
		var resp = struct{
 | 
			
		||||
			Data data `json:"data"`
 | 
			
		||||
		var resp = struct {
 | 
			
		||||
			Data    data `json:"data"`
 | 
			
		||||
			Success bool `json:"success"`
 | 
			
		||||
			Status int `json:"status"`
 | 
			
		||||
			Status  int  `json:"status"`
 | 
			
		||||
		}{
 | 
			
		||||
			Data: data{
 | 
			
		||||
				Link: fmt.Sprintf("https://%s/i/%s", r.Host, id),
 | 
			
		||||
			},
 | 
			
		||||
			Success: true,
 | 
			
		||||
			Status: 200,
 | 
			
		||||
			Status:  200,
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		json.NewEncoder(w).Encode(resp)
 | 
			
		||||
		err = json.NewEncoder(w).Encode(resp)
 | 
			
		||||
		span.RecordError(err)
 | 
			
		||||
 | 
			
		||||
	default:
 | 
			
		||||
		http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
 | 
			
		||||
@ -165,6 +172,7 @@ func (a *image) put(ctx context.Context, w http.ResponseWriter, r io.ReadCloser,
 | 
			
		||||
	rdr := io.LimitReader(r, a.maxSize)
 | 
			
		||||
	pr := readutil.NewPreviewReader(rdr)
 | 
			
		||||
	if !isImageOrVideo(pr) {
 | 
			
		||||
		span.AddEvent("not image")
 | 
			
		||||
		return "", ErrUnsupportedType
 | 
			
		||||
	}
 | 
			
		||||
	rdr = pr.Drain()
 | 
			
		||||
@ -172,6 +180,7 @@ func (a *image) put(ctx context.Context, w http.ResponseWriter, r io.ReadCloser,
 | 
			
		||||
	s256 := sha256.New()
 | 
			
		||||
	tmp, err := os.CreateTemp(a.store, "image-")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		span.RecordError(err)
 | 
			
		||||
		return "", fmt.Errorf("%w: %w", ErrBadInput, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -179,6 +188,7 @@ func (a *image) put(ctx context.Context, w http.ResponseWriter, r io.ReadCloser,
 | 
			
		||||
 | 
			
		||||
	m := io.MultiWriter(s256, tmp)
 | 
			
		||||
	if _, err := io.Copy(m, rdr); err != nil {
 | 
			
		||||
		span.RecordError(err)
 | 
			
		||||
		return "", fmt.Errorf("%w: %w", ErrBadInput, err)
 | 
			
		||||
	}
 | 
			
		||||
	tmp.Close()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user