2022-08-11 19:24:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of goboru. (https://git.redxen.eu/caskd/goboru)
|
|
|
|
* Copyright (c) 2022 Alex-David Denes
|
|
|
|
*
|
|
|
|
* goboru is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* goboru is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with goboru. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-05-10 20:15:01 +00:00
|
|
|
package goboru
|
|
|
|
|
|
|
|
import (
|
2022-08-11 19:24:05 +00:00
|
|
|
"errors"
|
2022-05-10 20:15:01 +00:00
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2022-08-11 19:24:05 +00:00
|
|
|
type Tags []string
|
|
|
|
type Jobs uint
|
2022-10-11 07:27:39 +00:00
|
|
|
type QueryFunc (func(Tags, Jobs) ([]Media, error))
|
2022-08-11 19:24:05 +00:00
|
|
|
|
2022-05-10 20:15:01 +00:00
|
|
|
type Media struct {
|
|
|
|
Source string
|
|
|
|
MD5 string
|
|
|
|
Tags []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m Media) Content() (rc io.ReadCloser, err error) {
|
2022-08-11 19:24:05 +00:00
|
|
|
if m.Source == "" {
|
|
|
|
err = errors.New("This media has no content")
|
|
|
|
}
|
2022-05-10 20:15:01 +00:00
|
|
|
client := http.Client{Timeout: 0, Transport: &http.Transport{ResponseHeaderTimeout: 10 * time.Second}}
|
|
|
|
|
|
|
|
var resp *http.Response
|
|
|
|
if resp, err = client.Get(m.Source); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
rc = resp.Body
|
|
|
|
return
|
|
|
|
}
|