api: isImageExists now returns false if the image does not exist in the target path or database
This commit is contained in:
parent
b2f3c9bbdf
commit
547e73846d
|
@ -276,22 +276,14 @@ func (api *API) isImageExists(ctx context.Context, post reddit.Post, device *mod
|
||||||
ctx, span := tracer.Start(ctx, "*API.IsImageExists")
|
ctx, span := tracer.Start(ctx, "*API.IsImageExists")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
_, err := models.Images.Query(ctx, api.db,
|
_, errQuery := models.Images.Query(ctx, api.db,
|
||||||
models.SelectWhere.Images.DeviceID.EQ(device.ID),
|
models.SelectWhere.Images.DeviceID.EQ(device.ID),
|
||||||
models.SelectWhere.Images.PostID.EQ(post.GetID()),
|
models.SelectWhere.Images.PostID.EQ(post.GetID()),
|
||||||
).One()
|
).One()
|
||||||
if err != nil {
|
|
||||||
if err.Error() == "sql: no rows in result set" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Image does not exist in target path.
|
_, errStat := os.Stat(post.GetImageTargetPath(api.config, device))
|
||||||
if _, err := os.Stat(post.GetImageTargetPath(api.config, device)); err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return errQuery == nil && errStat == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldDownloadPostForDevice(post reddit.Post, device *models.Device) bool {
|
func shouldDownloadPostForDevice(post reddit.Post, device *models.Device) bool {
|
||||||
|
|
Loading…
Reference in a new issue