scratch – Diff between revs 124 and 139

Subversion Repositories:
Rev:
Show entire fileRegard whitespace
Rev 124 Rev 139
Line 12... Line 12...
12 require_once('vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/FFMpeg.php'); 12 require_once('vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/FFMpeg.php');
Line 13... Line 13...
13   13  
14 ### Load configuration. 14 ### Load configuration.
Line -... Line 15...
-   15 $config = spyc_load_file('config.yaml');
-   16  
-   17 ### If tags were specified then check whether the hash matches any tags.
-   18 $tags = array();
-   19 if(isset($_GET['tags']) && !empty($_GET['tags'])) {
-   20 ## Extract the token field values.
-   21 $tags = array_filter(
-   22 array_map(
-   23 function($item) {
-   24 return $item->value;
-   25 },
-   26 array_values(
-   27 json_decode(
-   28 stripslashes(
-   29 $_GET['tags']
-   30 )
-   31 )
-   32 )
-   33 )
-   34 );
-   35
-   36 ## Connect or create the scratch database.
-   37 $db = new PDO('sqlite:db/scratch.sqlite3');
-   38  
-   39 ## Set the error mode to exceptions.
-   40 $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-   41  
-   42 try {
-   43 $db->beginTransaction();
-   44
-   45 ## Create tags table if it does not exist.
-   46 $db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE, UNIQUE("hash", "tag") ON CONFLICT REPLACE)');
-   47
-   48 ## Select all the hashes that match supplied tags.
-   49 $q = $db->prepare('SELECT "hash" FROM "tags" WHERE tag IN ('.implode(',', array_fill(0, count($tags), '?')).')');
-   50 foreach($tags as $i => $tag)
-   51 $q->bindValue($i+1, $tag);
-   52
-   53 $result = $q->execute();
-   54 $tags = $q->fetchAll(PDO::FETCH_COLUMN, 0);
-   55 $db->commit();
-   56 } catch(Exception $e) {
-   57 error_log($e);
-   58 ## Rollback.
-   59 $db->rollback();
-   60 }
15 $config = spyc_load_file('config.yaml'); 61 }
16   62  
17 ### Open MIME. 63 ### Open MIME.
18 $finfo = finfo_open(FILEINFO_MIME_TYPE); 64 $finfo = finfo_open(FILEINFO_MIME_TYPE);
19 if (!$finfo) { 65 if (!$finfo) {
Line 23... Line 69...
23   69  
24 echo json_encode( 70 echo json_encode(
25 array_values( 71 array_values(
26 array_filter( 72 array_filter(
27 array_map( 73 array_map(
28 function ($file) use ($config, $finfo) { 74 function ($file) use ($config, $finfo, $tags) {
29 #### Get the file hash. 75 #### Get the file hash.
Line 30... Line 76...
30 $fileHash = array_shift(explode('.', $file)); 76 $fileHash = array_shift(explode('.', $file));
31 77
Line 102... Line 148...
102 $previewHash = $fileHash; 148 $previewHash = $fileHash;
103 break; 149 break;
104 default: 150 default:
105 return null; 151 return null;
106 } 152 }
-   153
-   154 if(!empty($tags) && !in_array($fileHash, $tags)) {
-   155 return array();
-   156 }
-   157
107 return array( 158 return array(
108 'url' => $fileHash, 159 'url' => $fileHash,
109 'type' => finfo_file($finfo, $userPath), 160 'type' => finfo_file($finfo, $userPath),
110 'preview' => $previewHash, 161 'preview' => $previewHash,
111 'opengraph' => $opengraph 162 'opengraph' => $opengraph