Refactor+error image

pull/37/head
Varun Patil 2022-08-15 23:43:10 +00:00
parent 3f1f80a5dc
commit cfbbe0c567
7 changed files with 330 additions and 30 deletions

285
img/error.svg 100644
View File

@ -0,0 +1,285 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
sodipodi:docname="error.svg"
inkscape:version="1.1 (c68e22c387, 2021-05-23)"
version="1.1"
id="svg2"
viewBox="0 0 300 300"
height="300"
width="300"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs
id="defs4">
<linearGradient
id="linearGradient967"
inkscape:collect="always">
<stop
id="stop963"
offset="0"
style="stop-color:#c2c2c2;stop-opacity:1" />
<stop
id="stop965"
offset="1"
style="stop-color:#9f9f9f;stop-opacity:1" />
</linearGradient>
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3414"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
effect="spiro"
id="path-effect3410"
is_visible="true" />
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3406"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
effect="spiro"
id="path-effect3402"
is_visible="true" />
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3398"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
effect="spiro"
id="path-effect3392"
is_visible="true" />
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3388"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3372"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3368"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3364"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
effect="spiro"
id="path-effect3360"
is_visible="true" />
<inkscape:path-effect
lpeversion="0"
is_visible="true"
id="path-effect3346"
effect="spiro" />
<inkscape:path-effect
lpeversion="0"
effect="spiro"
id="path-effect3392-8"
is_visible="true" />
<linearGradient
gradientTransform="translate(-45.254833,0.35355338)"
gradientUnits="userSpaceOnUse"
y2="108.77648"
x2="658.45801"
y1="6.5995569"
x1="660.06653"
id="linearGradient969"
xlink:href="#linearGradient967"
inkscape:collect="always" />
</defs>
<sodipodi:namedview
inkscape:document-rotation="0"
inkscape:window-maximized="1"
inkscape:window-y="-9"
inkscape:window-x="-9"
inkscape:window-height="991"
inkscape:window-width="1920"
units="px"
fit-margin-bottom="0"
fit-margin-right="0"
fit-margin-left="0"
fit-margin-top="0"
inkscape:guide-bbox="true"
inkscape:snap-smooth-nodes="true"
showguides="false"
inkscape:object-nodes="true"
showgrid="false"
inkscape:current-layer="layer1"
inkscape:document-units="px"
inkscape:cy="109.60155"
inkscape:cx="149.19953"
inkscape:zoom="0.7071068"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
borderopacity="1.0"
bordercolor="#666666"
pagecolor="#ffffff"
id="base"
inkscape:pagecheckerboard="0">
<inkscape:grid
originy="-510.42818"
originx="-399.13435"
id="grid3336"
type="xygrid" />
<sodipodi:guide
id="guide3375"
orientation="0,1"
position="-117.13437,-25.564321" />
<sodipodi:guide
id="guide3377"
orientation="0,1"
position="-114.13437,-23.564321" />
<sodipodi:guide
id="guide3380"
orientation="0,1"
position="-121.13437,-27.564321" />
<sodipodi:guide
id="guide3382"
orientation="0,1"
position="-114.13437,-22.564321" />
<sodipodi:guide
id="guide3384"
orientation="0,1"
position="-114.13437,-21.564321" />
<sodipodi:guide
id="guide3416"
orientation="-2,0.5"
position="-115.13437,-25.564311" />
<sodipodi:guide
id="guide3420"
orientation="-2,0.5"
position="-115.13437,-25.564311" />
<sodipodi:guide
id="guide4180"
orientation="0.24382204,-0.96981999"
position="206.80442,220.41193" />
<sodipodi:guide
id="guide4182"
orientation="1,0"
position="86.804424,280.52227" />
<sodipodi:guide
id="guide4186"
orientation="1,0"
position="206.80442,250.52231" />
<sodipodi:guide
id="guide4188"
orientation="-0.24382199,0.96982"
position="206.80442,190.30156" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
transform="translate(-399.13437,-122.79051)"
id="layer1"
inkscape:groupmode="layer"
inkscape:label="Layer 1">
<g
transform="translate(38.121319,203.76955)"
id="g1015">
<rect
style="fill:#9f9f9f;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:2.2995;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect1002"
width="82.489967"
height="90.470001"
x="398.75827"
y="178.74706"
ry="8.3970251"
transform="rotate(-16.342822)" />
<g
id="g1000"
transform="rotate(16.320529,538.13563,-184.89727)">
<rect
ry="4.5961938"
y="1.6498091"
x="547.18585"
height="115.96551"
width="107.83378"
id="rect961"
style="fill:url(#linearGradient969);fill-opacity:1;fill-rule:nonzero;stroke:#ffffff;stroke-width:5.398;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<g
style="stroke:#ffffff;stroke-width:13.0708;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.17265471,0,0,0.17265471,512.49324,-6.3296456)"
id="g875">
<rect
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#cccccc;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:13.0708;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect3338"
width="491.10556"
height="449.99814"
x="270"
y="107.36227" />
<rect
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:13.0708;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
id="rect3342"
width="491.10559"
height="209.99976"
x="270"
y="107.36227" />
<path
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#cccccc;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:13.0708;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;paint-order:stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 300,317.36255 38.46147,-53.53818 60.53097,-45.16084 15.88277,18.57394 13.61285,-38.68356 8.20133,-2.98188 13.3106,-28.2093 180,179.99979"
id="path3344"
inkscape:path-effect="#path-effect3346"
inkscape:original-d="m 300,317.36255 38.46147,-53.53818 60.53097,-45.16084 15.88277,18.57394 13.61285,-38.68356 8.20133,-2.98188 13.3106,-28.2093 180,179.99979"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccc" />
<path
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#b3b3b3;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:13.0708;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;paint-order:stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 180,60 c 4.09311,16.474688 7.71219,33.067277 10.85156,49.75 2.38256,12.66097 4.48857,25.37408 6.31641,38.12695 l -22.06445,-7.16015 -46.11133,-29.41602 5.32422,46.42578 -1.61524,24.78711 10.05274,30.37695 73.18554,-11.75585 L 300,180 252.19922,102.56641 242.5,117.5 215.375,95.375 Z"
transform="translate(270,107.36227)"
id="path3390-0"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cscccccccccccc" />
<path
inkscape:connector-curvature="0"
inkscape:original-d="m 419.99999,347.36252 81.89918,-74.42959 18.50574,-9.68009 23.6512,-44.18894 25.94388,-21.70121 179.99999,179.99979"
inkscape:path-effect="#path-effect3360"
id="path3358"
d="m 419.99999,347.36252 81.89918,-74.42959 18.50574,-9.68009 23.6512,-44.18894 25.94388,-21.70121 179.99999,179.99979"
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#cccccc;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:13.0708;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;paint-order:stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
sodipodi:nodetypes="cccccc" />
<path
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#b3b3b3;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:13.0708;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;paint-order:stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 569.99999,197.36269 35.9388,80.91289 v 30.11038 30.11038 l 22.45864,19.46652 c 6.52453,-6.45031 14.14893,-11.78526 22.44431,-15.70477 14.8245,-7.00447 31.33823,-9.35959 47.17057,-13.6217 6.42776,-1.73037 12.90672,-3.85419 18.21343,-7.87277 1.35174,-1.02362 2.61592,-2.16281 3.77424,-3.40107 h -30 l -40.52149,-40.55006 -29.85645,-48.91972 -10.25307,8.83886 z"
id="path3386"
inkscape:path-effect="#path-effect3388"
inkscape:original-d="m 569.99999,197.36269 35.9388,80.91289 v 30.11038 30.11038 l 22.45864,19.46652 c 5.77311,-6.36416 13.54339,-11.40815 22.44431,-15.70477 13.00316,-6.27685 32.0432,-8.74899 47.17057,-13.6217 6.8762,-2.21491 12.68001,-4.81998 18.21343,-7.87277 1.55883,-0.86001 1.99765,-2.671 3.77424,-3.40107 h -30 l -40.52149,-40.55006 -29.85645,-48.91972 -10.25307,8.83886 z"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccssscccccc" />
<path
style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;fill:#ffffff;fill-opacity:1;fill-rule:evenodd;stroke:#ffffff;stroke-width:13.0708;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;paint-order:stroke;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
d="m 419.99999,557.36227 c -0.41699,-9.60089 -8.81759,-17.60878 17.1252,-30.66806 31.8318,-16.02389 125.895,-35.88836 152.1537,-59.98434 19.42709,-17.82687 -70.4154,-37.66945 -55.0191,-59.07323 6.981,-9.70528 59.037,-19.96947 82.1463,-30.27386 21.90569,-9.76799 15.14129,-19.80328 31.4046,-29.97507 15.7092,-9.82558 68.3499,-19.77358 72.18929,-30.02516 -10.41359,10.52188 -68.83379,20.40327 -89.99999,30.00026 -22.3377,10.128 -21.4689,19.93018 -49.4313,29.48367 -30.1245,10.29239 -89.142,20.55268 -102.7077,30.51626 -28.4133,20.86858 46.863,42.59995 16.2024,59.99993 C 452.54309,490.92554 344.7219,510.65712 300,527.3626 c -30.9039,11.54369 -28.4079,17.74799 -30,29.99967"
id="path3370"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cssssscsssssc" />
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -39,6 +39,26 @@ use OCP\Files\Events\Node\NodeTouchedEvent;
class Application extends App implements IBootstrap {
public const APPNAME = 'betterphotos';
public const IMAGE_MIMES = [
'image/png',
'image/jpeg',
'image/heic',
// 'image/gif', // too rarely used for photos
// 'image/x-xbitmap', // too rarely used for photos
// 'image/bmp', // too rarely used for photos
// 'image/svg+xml', // too rarely used for photos
];
public const VIDEO_MIMES = [
// 'video/mpeg', // too rarely used for photos
// 'video/ogg', // too rarely used for photos
// 'video/webm', // too rarely used for photos
'video/mp4',
// 'video/x-m4v', // too rarely used for photos
'video/quicktime',
// 'video/x-matroska' // too rarely used for photos
];
public function __construct() {
parent::__construct(self::APPNAME);
}

View File

@ -77,7 +77,7 @@ class Index extends Command {
$this->config = $config;
$this->encryptionManager = $encryptionManager;
$this->connection = $connection;
$this->util = new \OCA\BetterPhotos\Db\Util($previewGenerator, $connection);
$this->util = new \OCA\BetterPhotos\Db\Util($connection);
try {
$this->globalService = $container->get(GlobalStoragesService::class);

View File

@ -40,6 +40,7 @@ class ApiController extends Controller {
private IConfig $config;
private IUserSession $userSession;
private IDBConnection $connection;
private \OCA\BetterPhotos\Db\Util $util;
public function __construct(
IRequest $request,
@ -52,6 +53,7 @@ class ApiController extends Controller {
$this->config = $config;
$this->userSession = $userSession;
$this->connection = $connection;
$this->util = new \OCA\BetterPhotos\Db\Util($this->connection);
}
/**
@ -66,7 +68,7 @@ class ApiController extends Controller {
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}
$list = \OCA\BetterPhotos\Db\Util::getDays($this->connection, $user->getUID());
$list = $this->util->getDays($user->getUID());
return new JSONResponse($list, Http::STATUS_OK);
}
@ -82,7 +84,7 @@ class ApiController extends Controller {
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
}
$list = \OCA\BetterPhotos\Db\Util::getDay($this->connection, $user->getUID(), intval($id));
$list = $this->util->getDay($user->getUID(), intval($id));
return new JSONResponse($list, Http::STATUS_OK);
}

View File

@ -3,31 +3,29 @@ declare(strict_types=1);
namespace OCA\BetterPhotos\Db;
use OCA\BetterPhotos\AppInfo\Application;
use OCP\Files\File;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IPreview;
class Util {
protected IPreview $previewGenerator;
protected IDBConnection $connection;
public function __construct(IPreview $previewGenerator,
IDBConnection $connection) {
$this->previewGenerator = $previewGenerator;
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}
public static function getDateTaken($file) {
// Attempt to read exif data
$exif = exif_read_data($file->fopen('rb'));
$dt = $exif['DateTimeOriginal'];
if ($dt) {
$dt = \DateTime::createFromFormat('Y:m:d H:i:s', $dt);
if ($dt) {
return $dt->getTimestamp();
}
}
if (in_array($file->getMimeType(), Application::IMAGE_MIMES)) {
$exif = exif_read_data($file->fopen('rb'));
$dt = $exif['DateTimeOriginal'];
if ($dt) {
$dt = \DateTime::createFromFormat('Y:m:d H:i:s', $dt);
if ($dt) {
return $dt->getTimestamp();
}
}
}
// Fall back to creation time
$dateTaken = $file->getCreationTime();
@ -41,11 +39,7 @@ class Util {
public function processFile(string $user, File $file, bool $update): void {
$mime = $file->getMimeType();
if (!str_starts_with($mime, 'image/')) {
return;
}
if (!$this->previewGenerator->isMimeSupported($file->getMimeType())) {
if (!in_array($mime, Application::IMAGE_MIMES) && !in_array($mime, Application::VIDEO_MIMES)) {
return;
}
@ -96,11 +90,10 @@ class Util {
}
}
public static function getDays(
IDBConnection $connection,
public function getDays(
string $user,
): array {
$qb = $connection->getQueryBuilder();
$qb = $this->connection->getQueryBuilder();
$qb->select('day_id', 'count')
->from('betterphotos_day')
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user)))
@ -110,8 +103,7 @@ class Util {
return $rows;
}
public static function getDay(
IDBConnection $connection,
public function getDay(
string $user,
int $dayId,
): array {
@ -121,7 +113,7 @@ class Util {
ON oc_filecache.fileid = oc_betterphotos.file_id
WHERE user_id = ? AND day_id = ?
ORDER BY date_taken DESC';
$rows = $connection->executeQuery($sql, [$user, $dayId], [
$rows = $this->connection->executeQuery($sql, [$user, $dayId], [
\PDO::PARAM_STR, \PDO::PARAM_INT,
]);
return $rows->fetchAll();

View File

@ -27,7 +27,7 @@ import Content from '@nextcloud/vue/dist/Components/Content'
import AppContent from '@nextcloud/vue/dist/Components/AppContent'
import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation'
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
import Timeline from './Timeline.vue'
import Timeline from './components/Timeline.vue'
export default {
name: 'App',

View File

@ -25,6 +25,7 @@
@click="openFile(img, item)"
:src="img.src" :key="img.file_id"
@load = "img.l = Math.random()"
@error="(e)=>e.target.src='img/error.svg'"
v-bind:style="{
width: rowHeight + 'px',
height: rowHeight + 'px',
@ -53,7 +54,7 @@
<script>
import * as dav from "./services/DavRequests";
import * as dav from "../services/DavRequests";
export default {
data() {