Add RemoteURL
and LocalFilename
to Images, remove Filename
This commit is contained in:
parent
9c9100d874
commit
d1ba8b48f3
@ -12,12 +12,12 @@ import (
|
||||
*/
|
||||
func (p Profile) SaveImage(img scraper.Image) error {
|
||||
_, err := p.DB.Exec(`
|
||||
insert into images (id, tweet_id, filename, is_downloaded)
|
||||
values (?, ?, ?, ?)
|
||||
insert into images (id, tweet_id, remote_url, local_filename, is_downloaded)
|
||||
values (?, ?, ?, ?, ?)
|
||||
on conflict do update
|
||||
set is_downloaded=?
|
||||
`,
|
||||
img.ID, img.TweetID, img.Filename, img.IsDownloaded,
|
||||
img.ID, img.TweetID, img.RemoteURL, img.LocalFilename, img.IsDownloaded,
|
||||
img.IsDownloaded,
|
||||
)
|
||||
return err
|
||||
@ -46,7 +46,7 @@ func (p Profile) SaveVideo(vid scraper.Video) error {
|
||||
* Get the list of images for a tweet
|
||||
*/
|
||||
func (p Profile) GetImagesForTweet(t scraper.Tweet) (imgs []scraper.Image, err error) {
|
||||
stmt, err := p.DB.Prepare("select id, filename, is_downloaded from images where tweet_id=?")
|
||||
stmt, err := p.DB.Prepare("select id, remote_url, local_filename, is_downloaded from images where tweet_id=?")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@ -58,7 +58,7 @@ func (p Profile) GetImagesForTweet(t scraper.Tweet) (imgs []scraper.Image, err e
|
||||
var img scraper.Image
|
||||
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&img.ID, &img.Filename, &img.IsDownloaded)
|
||||
err = rows.Scan(&img.ID, &img.RemoteURL, &img.LocalFilename, &img.IsDownloaded)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -61,7 +61,8 @@ create table urls (rowid integer primary key,
|
||||
create table images (rowid integer primary key,
|
||||
id integer unique not null check(typeof(id) = 'integer'),
|
||||
tweet_id integer not null,
|
||||
filename text not null unique,
|
||||
remote_url text not null unique,
|
||||
local_filename text not null unique,
|
||||
is_downloaded boolean default 0,
|
||||
|
||||
foreign key(tweet_id) references tweets(id)
|
||||
|
@ -66,7 +66,8 @@ func create_image_from_id(id int) scraper.Image {
|
||||
return scraper.Image{
|
||||
ID: scraper.ImageID(id),
|
||||
TweetID: -1,
|
||||
Filename: filename,
|
||||
RemoteURL: filename,
|
||||
LocalFilename: filename,
|
||||
IsDownloaded: false,
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ type ImageID int64
|
||||
type Image struct {
|
||||
ID ImageID
|
||||
TweetID TweetID
|
||||
Filename string
|
||||
RemoteURL string
|
||||
LocalFilename string
|
||||
IsDownloaded bool
|
||||
@ -19,13 +18,8 @@ func ParseAPIMedia(apiMedia APIMedia) Image {
|
||||
local_filename := path.Base(apiMedia.MediaURLHttps)
|
||||
return Image{
|
||||
ID: ImageID(apiMedia.ID),
|
||||
Filename: apiMedia.MediaURLHttps, // TODO filename
|
||||
RemoteURL: apiMedia.MediaURLHttps,
|
||||
LocalFilename: local_filename,
|
||||
IsDownloaded: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (img Image) FilenameWhenDownloaded() string {
|
||||
return path.Base(img.Filename)
|
||||
}
|
||||
|
@ -28,9 +28,6 @@ func TestParseAPIMedia(t *testing.T) {
|
||||
if image.RemoteURL != expected_remote_url {
|
||||
t.Errorf("Expected %q, got %q", expected_remote_url, image.RemoteURL)
|
||||
}
|
||||
if image.Filename != expected_remote_url { // XXX filename: delete this check
|
||||
t.Errorf("Expected %q, got %q", expected_remote_url, image.Filename)
|
||||
}
|
||||
expected_local_filename := "E18sEUrWYAk8dBl.jpg"
|
||||
if image.LocalFilename != expected_local_filename {
|
||||
t.Errorf("Expected %q, got %q", expected_local_filename, image.LocalFilename)
|
||||
|
Loading…
x
Reference in New Issue
Block a user