Git Product home page Git Product logo

dialog's Introduction

Dialog photoblog

Build status on GitHub Uses XP Framework BSD Licence Requires PHP 7.4+ Supports PHP 8.0+

See https://dialog.friebes.info/

Prerequisites

Setup

First, create the import user:

$ echo -n "secret-password-here" | sha256sum
4323135e32ac4...

# Copy the connection URI from MongoDB Atlas
$ mongosh mongodb+srv://[USER]:[PASSWORD]@[PROJECT].[ORG].mongodb.net
$ use dialog
$ db.users.insert({handle: "import", pass: "4323135e32ac4..."});
# ...

Store the connection string in a configuration file named config.ini:

[mongo]
uri=mongodb+srv://[USER]:[PASSWORD]@[PROJECT].[ORG].mongodb.net/?readPreference=nearest

Then, run composer to install PHP and JavaScript dependencies.

$ composer up
# ...

Running locally

Now, Dialog can be run locally.

$ xp serve
# ...

Open http://localhost:8080/ to see the empty page

Importing local directories

Next, we'll import some pictures:

$ xp import import-target/ http://import:pass@localhost:8080/api
# ...

Content

Expects the following directory structure:

import-target
|- content.md
|- image-1.jpg
|- image-2.jpg
`- image-(n).jpg

Journey

Expects the following directory structure:

import-target
|- journey.md
|- part-1
|  |- content.md
|  |- image-1.jpg
|  `- image-2.jpg
|- part-2
|  |- content.md
|  |- image-1.jpg
|  `- image-2.jpg
`- part-(n)

dialog's People

Contributors

thekid avatar

Stargazers

 avatar  avatar

Watchers

 avatar

dialog's Issues

Installation wizard

If freshly installed:

  • Ask user to create Atlas API key
  • Make user select filesystem location for media
  • Save this to an INI file
  • Create admin login
  • Create search indexes
  • Redirect to admin interface once #26 is implemented

Lighthouse score tracking issue

Starting point for /feed:

Lighthouse score

TODO:

  • Investigate deprecated APIs layers - see #17
  • Image dimensions when using cards or smaller images
  • Content Security Policy - #19

MongoDB error "not primary and secondaryOk=false"

Caused by Exception com.mongodb.Error (#13435:NotPrimaryNoSecondaryOk "not primary and secondaryOk=false")
  at com.mongodb.Error::newInstance(array[7]) [line 201 of Connection.class.php] 
  at com.mongodb.io.Connection::message(array[5], array[1]) [line 163 of Protocol.class.php] 
  at com.mongodb.io.Protocol::send(array[1], array[4], (0x14)'reading with primary') [line 205 of Protocol.class.php] 
  at com.mongodb.io.Protocol::read(NULL, array[4]) [line 235 of Collection.class.php] 
  at com.mongodb.Collection::aggregate(array[4]) [line 38 of Repository.php] 
  at de.thekid.dialog.Repository::entries(de.thekid.dialog.Pagination{}, 3) [line 14 of Feed.php] 
  at de.thekid.dialog.web.Feed::listing((0x1)'3') [line 0 of StackTraceElement.class.php] 
  at ReflectionMethod::invokeArgs(de.thekid.dialog.web.Feed{}, array[1]) [line 88 of Method.class.php] 
  at lang.reflect.Method::invoke(de.thekid.dialog.web.Feed{}, array[1]) [line 85 of Delegate.class.php] 
  ... 16 more

Admin interface

Create an admin interface to upload images and videos

  • Authentication
  • Upload via drag and drop
  • Upload folders?
  • Copy&paste images
  • Image processing - see #44
  • WYSIWYG editor for content

Step 1: Research which libraries we can use for this

Can we find out what the deprecated APIs are?

Lighthouse score

The 92 lighthouse score for "best practices" results from deprecated APIs. This warning doesn't appear on pages without a map, so it must come from the OpenLayers implementation somewhere.

Optimize Repository::entries() once MongoDB Atlas is running 5.2+

See comment in Repository::entries():

...
$cursor= $entries->aggregate([
  ['$match' => ['parent' => ['$eq' => null], 'published' => ['$lt' => Date::now()]]],
  ['$unset' => '_searchable'],
  ['$sort'  => ['date' => -1]],
  ['$skip'  => $pagination->skip($page)],
  ['$limit' => $pagination->limit()],
]);

// We could use $lookup here but would then not have the children sorted
// properly - $sortArray is not available until 5.2, and Atlas free tier
// currently runs 5.0. TODO: Change this once prerequisites are fully met!
$results= [];
foreach ($cursor as $entry) {
  if (empty($entry['images'])) {
    $children= $entries->aggregate([
      ['$match' => ['parent' => $entry['slug']]],
      ['$unset' => '_searchable'],
      ['$sort'  => ['date' => -1]],
      ['$limit' => $children],
    ]);
    $entry['children']= $children->all();
  }
  $results[]= $entry;
}
...
  • Wait for MongoDB Atlas free tier to have 5.2+ available
  • Rewrite above to use $lookup with $sortArray
  • Bonus: Figure out if there is a way to conditionally perform the lookup stage as done in the code above

Online media processing architecture

Purpose

This issue serves as a concept for an architecture which enables us to process uploaded media online. Key requirements:

Overview and flow

image

User uploads

Implemented inside the backstage area, see #26. Uploaded images are stored directly in the correct location (see below), and an entry in the processing collection is created:

{
  "slug":"rueppur_alb_2022-11-13",
  "file":"20221113_151718315_iOS.jpg",
  "at":{"$date":{"$numberLong":"1668873515000"}},
  "state":"new"
}

Media processor

Implemented in #46. Watches processing collection for entries with state = new, fetches uploaded images, extracts meta data and converts images to the correct sizes, then uploads all of that.

Media storage

Currently, media is stored right inside the folder for a given entry. Each variant has a prefix:

  • full - Full-size image (WebP, 3840 * x)
  • thumb - Thumbnail image (WebP, 1024 * x)
  • preview - Preview image (JPEG, 720 * x)
  • video - Video file (MPEG-4, H.264, 1920 * x)
/space/image
 |- rueppur_alb_2022-11-13
 |  |- full-20221113_151718315_iOS.jpg.webp
 |  |- preview-20221113_151718315_iOS.jpg.jpg
 |  `- thumb-20221113_151718315_iOS.jpg.webp
 |
 `- philippines-2006
    |- alona_white_beach-2006-09-06
    |  |- full...
    |  `- ...
    |- full...
    `- ...

The original uploads will be stored alongside these without any prefix, e.g. 20221113_151718315_iOS.jpg.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.