summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-02-23 20:31:19 +0100
committerJules Laplace <julescarbon@gmail.com>2021-02-23 20:31:19 +0100
commit464991b62e4fa6141449ca0c5980fcf0af3097a6 (patch)
tree18e597dc951cbf4605995e3aa1b1f8761449549f
parent19516de0a43ac5f2b0afc9891bbef09d229ce4e6 (diff)
upload files and write to diskv0.3.0
-rw-r--r--.gitignore2
-rw-r--r--Readme.md20
-rw-r--r--app/node_modules/okservices/oks3/index.js11
-rw-r--r--app/node_modules/okservices/oks3/upload.js78
-rw-r--r--examples/db.json12
-rw-r--r--examples/index.js12
-rw-r--r--examples/templates/index.liquid4
-rw-r--r--themes/okadmin/public/js/app.js6
-rw-r--r--themes/okadmin/public/js/parser.js608
-rw-r--r--themes/okadmin/public/js/upload.js12
-rw-r--r--themes/okadmin/templates/partials/inputs.liquid2
11 files changed, 459 insertions, 308 deletions
diff --git a/.gitignore b/.gitignore
index e2282ba..6e7ce41 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,4 +8,6 @@
.tmp
npm-debug.log
site/public/decks/
+site/public/uploads/
+examples/public/uploads/
diff --git a/Readme.md b/Readme.md
index 53b190f..9d146e0 100644
--- a/Readme.md
+++ b/Readme.md
@@ -1,20 +1,19 @@
# OKCMS
> "Pretty good"
+>
> - Steve Jobs
-
## To run the demo:
-* npm install
-* cd examples
-* node index
+- npm install
+- cd examples
+- node index
Server will be running on http://lvh.me:1337/
Admin area available on http://lvh.me:1337/admin/
-
## Config
To access the admin area, you need to set a username and password.
@@ -27,6 +26,7 @@ OK_PASS=password
```
S3 needs to be configured in the same way:
+
```
S3_KEY=s3key
S3_SECRET=s3secret
@@ -73,3 +73,13 @@ Valid datatypes include:
- double-captioned-image-list
- meta
+## Local S3
+
+If you don't want to use S3 and you have enough disk space locally, you can just write them locally. Supply these options to the S3 service configuration (pathss with trailing slash!).
+
+```
+local: {
+ localPath: "/home/username/my-cool-website-pro/public/local-files/",
+ remotePath: "/local-files/",
+},
+```
diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js
index 41ee3dc..60567e9 100644
--- a/app/node_modules/okservices/oks3/index.js
+++ b/app/node_modules/okservices/oks3/index.js
@@ -46,6 +46,7 @@ function OKS3(options) {
key: options.s3.key,
secret: options.s3.secret,
bucket: options.s3.bucket,
+ local: options.s3.local,
})
var express = options.express;
@@ -85,7 +86,7 @@ function OKS3(options) {
router.post('/audio', mult.single('audio'), function(req, res) {
d.run(function () {
- if (! options.s3.image.allowed) {
+ if (! options.s3.audio.allowed) {
return res.status(500).json({ error: "Audio uploading not permitted" })
}
@@ -113,7 +114,7 @@ function OKS3(options) {
router.post('/video', mult.single('video'), function(req, res) {
d.run(function () {
- if (! options.s3.image.allowed) {
+ if (! options.s3.video.allowed) {
return res.status(500).json({ error: "Video uploading not permitted" })
}
@@ -140,7 +141,7 @@ function OKS3(options) {
router.post('/file', mult.single('file'), function(req, res) {
d.run(function () {
- if (! options.s3.image.allowed) {
+ if (! options.s3.file.allowed) {
return res.status(500).json({ error: "File uploading not permitted" })
}
@@ -149,6 +150,10 @@ function OKS3(options) {
preserveFilename: options.s3.video.preserveFilename,
dirname: options.s3.dirname,
types: {
+ 'image/gif': 'gif',
+ 'image/jpeg': 'jpg',
+ 'image/jpg': 'jpg',
+ 'image/png': 'png',
'application/pdf': 'pdf',
'text/plain': 'txt',
'text/html': 'html',
diff --git a/app/node_modules/okservices/oks3/upload.js b/app/node_modules/okservices/oks3/upload.js
index 681b14b..5d5c635 100644
--- a/app/node_modules/okservices/oks3/upload.js
+++ b/app/node_modules/okservices/oks3/upload.js
@@ -1,6 +1,8 @@
+var fs = require('fs')
var knox = require('knox')
var uuid = require('node-uuid')
+var crypto = require('crypto')
var s3
@@ -15,11 +17,15 @@ var acceptableuploadTypes = {
module.exports = {}
module.exports.init = function (opt){
- s3 = knox.createClient({
- key: opt.key,
- secret: opt.secret,
- bucket: opt.bucket,
- })
+ if (opt.local) {
+ s3 = { local: opt.local }
+ } else {
+ s3 = knox.createClient({
+ key: opt.key,
+ secret: opt.secret,
+ bucket: opt.bucket,
+ })
+ }
}
module.exports.put = function (opt) {
@@ -28,10 +34,11 @@ module.exports.put = function (opt) {
var now = new Date()
var file = opt.file
+ // console.log("Received", file.originalname, file.mimetype)
var types = opt.types || acceptableuploadTypes
var extension = types[file.mimetype]
-
+
if (opt.filename) {
filename = opt.filename
}
@@ -60,24 +67,49 @@ module.exports.put = function (opt) {
opt.acceptable && opt.acceptable(err)
// console.log("upload >", remote_path)
- s3.putBuffer(file.buffer, remote_path, {
- 'Content-Length': file.size,
- 'Content-Type': file.mimetype,
- 'x-amz-acl': 'public-read'
- }, function(err, s3res) {
- if (err || s3res.statusCode !== 200) {
- console.error(err);
- if (s3res && s3res.resume) {
- s3res.resume()
+ if (s3.local) {
+ var hash = crypto.createHash("sha256").update(filename, "utf8").digest("hex")
+ var hash_path = hash.substr(0, 2)
+ fs.mkdir(s3.local.localPath + hash_path, function(error){
+ if (error && error.code !== "EEXIST") {
+ console.error("error creating directory")
+ console.error(error)
+ opt.unacceptable && opt.unacceptable(error)
+ return
+ }
+ var localPath = (s3.local.localPath + hash_path + "/" + filename).replace(/\/\//g, "/")
+ var remotePath = (s3.local.remotePath + hash_path + "/" + filename).replace(/\/\//g, "/")
+ fs.writeFile(localPath, file.buffer, {}, function(error){
+ if (error) {
+ console.error("error saving file")
+ console.error(error)
+ opt.unacceptable && opt.unacceptable(error)
+ return
+ }
+ opt.success && opt.success(remotePath)
+ });
+ })
+ } else {
+ s3.putBuffer(file.buffer, remote_path, {
+ 'Content-Length': file.size,
+ 'Content-Type': file.mimetype,
+ 'x-amz-acl': 'public-read'
+ }, function(err, s3res) {
+ if (err || s3res.statusCode !== 200) {
+ console.error(err);
+ if (s3res && s3res.resume) {
+ s3res.resume()
+ }
+ return;
}
- return;
- }
- var file_url = s3res.url || s3res.req.url
+ var file_url = s3res.url || s3res.req.url
- opt.success && opt.success(file_url)
- }).on('error', function(err, s3res){
- console.error(err)
- s3res && s3res.resume && s3res.resume()
- })
+ opt.success && opt.success(file_url)
+ }).on('error', function(err, s3res){
+ console.error(err)
+ s3res && s3res.resume && s3res.resume()
+ })
+ }
}
+
diff --git a/examples/db.json b/examples/db.json
index 34304c9..11204e7 100644
--- a/examples/db.json
+++ b/examples/db.json
@@ -328,5 +328,17 @@
"dateCreated": "Sat, 31 Dec 2016 05:07:09 GMT",
"images": []
}
+ ],
+ "filez": [
+ {
+ "id": "pdf-upload",
+ "title": "PDF upload",
+ "file": {
+ "uri": "/uploads/1e/Typhon firmware v3.pdf",
+ "caption": "/uploads/1e/Typhon firmware v3.pdf"
+ },
+ "__index": 0,
+ "dateCreated": "Tue, 23 Feb 2021 19:30:32 GMT"
+ }
]
} \ No newline at end of file
diff --git a/examples/index.js b/examples/index.js
index f08c752..729c574 100644
--- a/examples/index.js
+++ b/examples/index.js
@@ -69,6 +69,11 @@ var app = okcms
image: { type: "image" },
images: { type: "triple-captioned-image-list" },
},
+ filez: {
+ id: { type: "string", hidden: true },
+ title: { type: "string" },
+ file: { type: "file" },
+ },
},
resources: [
@@ -77,6 +82,7 @@ var app = okcms
{ type: "bread" },
{ type: "test" },
{ type: "flour" },
+ { type: "filez" },
],
services: {
@@ -85,6 +91,10 @@ var app = okcms
secret: process.env.S3_SECRET,
bucket: process.env.S3_BUCKET,
dirname: "okcms-example",
+ local: {
+ localPath: "/Users/user/Sites/okcms/examples/public/uploads/",
+ remotePath: "/uploads/",
+ },
image: {
allowed: true,
preserveFilename: false,
@@ -163,7 +173,7 @@ var app = okcms
"/contact": {
data: { type: "page", query: "contact" },
},
- "/:id": {
+ "/bread/:id": {
data: { type: "bread", query: ":id" },
},
},
diff --git a/examples/templates/index.liquid b/examples/templates/index.liquid
index 7c12a86..4f26378 100644
--- a/examples/templates/index.liquid
+++ b/examples/templates/index.liquid
@@ -12,7 +12,7 @@
<nav>
<ul>
{% for page in pages %}
- <li><a href="{{page.id}}">{{page.id | capitalize}}</a></li>
+ <li><a href="/{{page.id}}">{{page.id | capitalize}}</a></li>
{% endfor %}
</ul>
<nav>
@@ -20,7 +20,7 @@
<h2>Great breads:</h2>
<ul>
{% for bread in breads %}
- <li><a href="{{bread.id}}">{{bread.id | capitalize}}</a></li>
+ <li><a href="/bread/{{bread.id}}">{{bread.id | capitalize}}</a></li>
{% endfor %}
</ul>
</div>
diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js
index dd6513a..da93e8b 100644
--- a/themes/okadmin/public/js/app.js
+++ b/themes/okadmin/public/js/app.js
@@ -173,10 +173,10 @@ var OKAdmin = function () {
var $el = $(this);
var uploader = new OKUpload();
uploader.bind(this);
- uploader.add = function (media) {
- console.log(media);
+ uploader.addMedia = function (media) {
+ console.log("file uploaded >>", media);
$el.find(".uri").val(media.url);
- $el.find(".caption").val("");
+ $el.find(".caption").val(media.url);
$el.find("a").attr("href", media.url).show();
$el.addClass("loaded");
};
diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js
index 81bba2d..ad1fc58 100644
--- a/themes/okadmin/public/js/parser.js
+++ b/themes/okadmin/public/js/parser.js
@@ -1,313 +1,387 @@
var Parser = {
- integrations: [{
- type: 'image',
- regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i,
- fetch: function(url, done) {
- var img = new Image ()
- img.onload = function(){
- if (!img) return
- var width = img.naturalWidth, height = img.naturalHeight
- img = null
- done({
- url: url,
- type: "image",
- token: "",
- thumbnail: "",
- title: "",
- width: width,
- height: height,
- })
- }
- img.src = url
- if (img.complete) {
- img.onload()
- }
- },
- tag: function (media) {
- return '<img src="' + media.url + '">';
- }
- }, {
- type: 'video',
- regex: /\.(mp4|webm)(\?.*)?$/i,
- fetch: function(url, done) {
- var video = document.createElement("video")
- var url_parts = url.replace(/\?.*$/, "").split("/")
- var filename = url_parts[ url_parts.length-1 ]
- video.addEventListener("loadedmetadata", function(){
- var width = video.videoWidth, height = video.videoHeight
- video = null
- done({
- url: url,
- type: "video",
- token: url,
- thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png",
- title: filename,
- width: width,
- height: height,
- })
- })
- video.src = url
- video.load()
- },
- tag: function (media) {
- return '<video src="' + media.url + '">';
- }
- }, {
- type: 'audio',
- regex: /\.(wav|mp3)(\?.*)?$/i,
- fetch: function(url, done) {
- var audio = document.createElement("audio")
- var url_parts = url.replace(/\?.*$/, "").split("/")
- var filename = url_parts[ url_parts.length-1 ]
- audio.addEventListener("loadedmetadata", function(){
- var duration = audio.duration
- audio = null
- done({
- url: url,
- type: "audio",
- token: url,
- thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/audio.png",
- title: filename,
- duration: duration,
- })
- })
- audio.src = url
- audio.load()
- },
- tag: function (media) {
- return '<audio src="' + media.url + '">';
- }
- }, {
- type: 'youtube',
- regex: /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i,
- fetch: function(url, done) {
- var id = (url.match(/v=([-_a-zA-Z0-9]{11})/i) || url.match(/youtu.be\/([-_a-zA-Z0-9]{11})/i) || url.match(/embed\/([-_a-zA-Z0-9]{11})/i))[1].split('&')[0];
- var thumb = "http://i.ytimg.com/vi/" + id + "/hqdefault.jpg"
- $.ajax({
- type: 'GET',
- url: 'https://www.googleapis.com/youtube/v3/videos',
- dataType: "jsonp",
- data: {
- id: id,
- key: "AIzaSyDYPKGD0-_VRBWpUYRmX8Qg6BtWmcPU_cM",
- part: "id,contentDetails,snippet,status",
- },
- success: function(result){
- var res = result.items[0]
- done({
- url: url,
- type: "youtube",
- token: id,
- thumbnail: thumb,
- title: res.snippet.title,
- autoplay: false,
- loop: false,
- width: 640,
- height: 360,
- })
- }
- })
- },
- tag: function (media) {
- // return '<img class="video" type="youtube" vid="'+media.token+'" src="'+media.thumbnail+'"><span class="playvid">&#9654;</span>';
- return '<div class="video" style="width: ' + media.width + 'px; height: ' + media.height + 'px; overflow: hidden; position: relative;"><iframe frameborder="0" scrolling="no" seamless="seamless" webkitallowfullscreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowfullscreen="allowfullscreen" id="okplayer" width="' + media.width + '" height="' + media.height + '" src="http://youtube.com/embed/' + media.token + '?showinfo=0" style="position: absolute; top: 0px; left: 0px; width: ' + media.width + 'px; height: ' + media.height + 'px;"></iframe></div>'
- }
- }, {
- type: 'vimeo',
- regex: /vimeo.com\/\d+$/i,
- fetch: function(url, done) {
- var id = url.match(/\d+$/i)[0];
- $.ajax({
- type: 'GET',
- url: 'http://vimeo.com/api/v2/video/' + id + '.json',
- success: function(result){
- if (result.length == 0) { return done(id, "", 640, 360) }
- var res = result[0]
- if (res.embed_privacy != "anywhere") {
- AlertModal.alert("Sorry, the author of this video has marked it private, preventing it from being embedded.", function(){})
- return
- }
- done({
- url: url,
- type: "vimeo",
- token: id,
- thumbnail: res.thumbnail_large,
- title: res.title,
- width: res.width,
- height: res.height,
- autoplay: false,
- loop: false,
- })
- }
- })
- },
- tag: function (media) {
- // return '<img class="video" type="vimeo" vid="'+media.token+'" src="'+media.thumbnail+'"><span class="playvid">&#9654;</span>';
- return '<div class="video" style="width: ' + media.width + 'px; height: ' + media.height + 'px; overflow: hidden; position: relative;"><iframe frameborder="0" scrolling="no" seamless="seamless" webkitallowfullscreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowfullscreen="allowfullscreen" id="okplayer" src="http://player.vimeo.com/video/' + media.token + '?api=1&title=0&byline=0&portrait=0&playbar=0&player_id=okplayer&loop=0&autoplay=0" width="' + media.width + '" height="' + media.height + '" style="position: absolute; top: 0px; left: 0px; width: ' + media.width + 'px; height: ' + media.height + 'px;"></iframe></div>'
- }
- }, {
- type: 'soundcloud',
- regex: /soundcloud.com\/[-a-zA-Z0-9]+\/[-a-zA-Z0-9]+\/?$/i,
- fetch: function (url, done) {
- $.ajax({
- type: 'GET',
- url: 'http://api.soundcloud.com/resolve.json?url='
- + url
- + '&client_id='
- + '0673fbe6fc794a7750f680747e863b10',
- success: function(result) {
- console.log(result)
- done({
- url: url,
- type: "soundcloud",
- token: result.id,
- thumbnail: result.artwork_url || result.user.avatar_url,
- title: result.user.username + " - " + result.title,
- duration: result.duration,
- width: 166,
- height: 166,
- })
- }
- });
- },
- tag: function (media) {
- return '<iframe width="166" height="166" scrolling="no" frameborder="no"' +
- 'src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' + media.token +
- '&amp;color=ff6600&amp;auto_play=false&amp;show_artwork=true"></iframe>'
- }
- },
- {
- type: 'link',
- regex: /^http.+/i,
- fetch: function(url, done) {
- done({
- url: url,
- type: "link",
- token: "",
- thumbnail: "",
- title: "",
- width: 100,
- height: 100,
- })
- },
- tag: function (media) {
- return '<a href="' + media.url + '" target="_blank">' + media.url + '</a>'
- }
- },
- ],
+ integrations: [
+ {
+ type: "image",
+ regex: /\.(jpeg|jpg|gif|png|svg)(\?.*)?$/i,
+ fetch: function (url, done) {
+ var img = new Image();
+ img.onload = function () {
+ if (!img) return;
+ var width = img.naturalWidth,
+ height = img.naturalHeight;
+ img = null;
+ done({
+ url: url,
+ type: "image",
+ token: "",
+ thumbnail: "",
+ title: "",
+ width: width,
+ height: height,
+ });
+ };
+ img.src = url;
+ if (img.complete) {
+ img.onload();
+ }
+ },
+ tag: function (media) {
+ return '<img src="' + media.url + '">';
+ },
+ },
+ {
+ type: "video",
+ regex: /\.(mp4|webm)(\?.*)?$/i,
+ fetch: function (url, done) {
+ var video = document.createElement("video");
+ var url_parts = url.replace(/\?.*$/, "").split("/");
+ var filename = url_parts[url_parts.length - 1];
+ video.addEventListener("loadedmetadata", function () {
+ var width = video.videoWidth,
+ height = video.videoHeight;
+ video = null;
+ done({
+ url: url,
+ type: "video",
+ token: url,
+ thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png",
+ title: filename,
+ width: width,
+ height: height,
+ });
+ });
+ video.src = url;
+ video.load();
+ },
+ tag: function (media) {
+ return '<video src="' + media.url + '">';
+ },
+ },
+ {
+ type: "audio",
+ regex: /\.(wav|mp3)(\?.*)?$/i,
+ fetch: function (url, done) {
+ var audio = document.createElement("audio");
+ var url_parts = url.replace(/\?.*$/, "").split("/");
+ var filename = url_parts[url_parts.length - 1];
+ audio.addEventListener("loadedmetadata", function () {
+ var duration = audio.duration;
+ audio = null;
+ done({
+ url: url,
+ type: "audio",
+ token: url,
+ thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/audio.png",
+ title: filename,
+ duration: duration,
+ });
+ });
+ audio.src = url;
+ audio.load();
+ },
+ tag: function (media) {
+ return '<audio src="' + media.url + '">';
+ },
+ },
+ {
+ type: "youtube",
+ regex: /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i,
+ fetch: function (url, done) {
+ var id = (url.match(/v=([-_a-zA-Z0-9]{11})/i) ||
+ url.match(/youtu.be\/([-_a-zA-Z0-9]{11})/i) ||
+ url.match(/embed\/([-_a-zA-Z0-9]{11})/i))[1].split("&")[0];
+ var thumb = "http://i.ytimg.com/vi/" + id + "/hqdefault.jpg";
+ $.ajax({
+ type: "GET",
+ url: "https://www.googleapis.com/youtube/v3/videos",
+ dataType: "jsonp",
+ data: {
+ id: id,
+ key: "AIzaSyDYPKGD0-_VRBWpUYRmX8Qg6BtWmcPU_cM",
+ part: "id,contentDetails,snippet,status",
+ },
+ success: function (result) {
+ var res = result.items[0];
+ done({
+ url: url,
+ type: "youtube",
+ token: id,
+ thumbnail: thumb,
+ title: res.snippet.title,
+ autoplay: false,
+ loop: false,
+ width: 640,
+ height: 360,
+ });
+ },
+ });
+ },
+ tag: function (media) {
+ // return '<img class="video" type="youtube" vid="'+media.token+'" src="'+media.thumbnail+'"><span class="playvid">&#9654;</span>';
+ return (
+ '<div class="video" style="width: ' +
+ media.width +
+ "px; height: " +
+ media.height +
+ 'px; overflow: hidden; position: relative;"><iframe frameborder="0" scrolling="no" seamless="seamless" webkitallowfullscreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowfullscreen="allowfullscreen" id="okplayer" width="' +
+ media.width +
+ '" height="' +
+ media.height +
+ '" src="http://youtube.com/embed/' +
+ media.token +
+ '?showinfo=0" style="position: absolute; top: 0px; left: 0px; width: ' +
+ media.width +
+ "px; height: " +
+ media.height +
+ 'px;"></iframe></div>'
+ );
+ },
+ },
+ {
+ type: "vimeo",
+ regex: /vimeo.com\/\d+$/i,
+ fetch: function (url, done) {
+ var id = url.match(/\d+$/i)[0];
+ $.ajax({
+ type: "GET",
+ url: "http://vimeo.com/api/v2/video/" + id + ".json",
+ success: function (result) {
+ if (result.length == 0) {
+ return done(id, "", 640, 360);
+ }
+ var res = result[0];
+ if (res.embed_privacy != "anywhere") {
+ AlertModal.alert(
+ "Sorry, the author of this video has marked it private, preventing it from being embedded.",
+ function () {}
+ );
+ return;
+ }
+ done({
+ url: url,
+ type: "vimeo",
+ token: id,
+ thumbnail: res.thumbnail_large,
+ title: res.title,
+ width: res.width,
+ height: res.height,
+ autoplay: false,
+ loop: false,
+ });
+ },
+ });
+ },
+ tag: function (media) {
+ // return '<img class="video" type="vimeo" vid="'+media.token+'" src="'+media.thumbnail+'"><span class="playvid">&#9654;</span>';
+ return (
+ '<div class="video" style="width: ' +
+ media.width +
+ "px; height: " +
+ media.height +
+ 'px; overflow: hidden; position: relative;"><iframe frameborder="0" scrolling="no" seamless="seamless" webkitallowfullscreen="webkitAllowFullScreen" mozallowfullscreen="mozallowfullscreen" allowfullscreen="allowfullscreen" id="okplayer" src="http://player.vimeo.com/video/' +
+ media.token +
+ '?api=1&title=0&byline=0&portrait=0&playbar=0&player_id=okplayer&loop=0&autoplay=0" width="' +
+ media.width +
+ '" height="' +
+ media.height +
+ '" style="position: absolute; top: 0px; left: 0px; width: ' +
+ media.width +
+ "px; height: " +
+ media.height +
+ 'px;"></iframe></div>'
+ );
+ },
+ },
+ {
+ type: "soundcloud",
+ regex: /soundcloud.com\/[-a-zA-Z0-9]+\/[-a-zA-Z0-9]+\/?$/i,
+ fetch: function (url, done) {
+ $.ajax({
+ type: "GET",
+ url:
+ "http://api.soundcloud.com/resolve.json?url=" +
+ url +
+ "&client_id=" +
+ "0673fbe6fc794a7750f680747e863b10",
+ success: function (result) {
+ console.log(result);
+ done({
+ url: url,
+ type: "soundcloud",
+ token: result.id,
+ thumbnail: result.artwork_url || result.user.avatar_url,
+ title: result.user.username + " - " + result.title,
+ duration: result.duration,
+ width: 166,
+ height: 166,
+ });
+ },
+ });
+ },
+ tag: function (media) {
+ return (
+ '<iframe width="166" height="166" scrolling="no" frameborder="no"' +
+ 'src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/' +
+ media.token +
+ '&amp;color=ff6600&amp;auto_play=false&amp;show_artwork=true"></iframe>'
+ );
+ },
+ },
+ {
+ type: "pdf",
+ regex: /\.pdf$/i,
+ fetch: function (url, done) {
+ done({
+ url: url,
+ type: "link",
+ token: "",
+ thumbnail: "",
+ title: "",
+ width: 100,
+ height: 100,
+ });
+ },
+ tag: function (media) {
+ return (
+ '<a href="' + media.url + '" target="_blank">' + media.url + "</a>"
+ );
+ },
+ },
+ {
+ type: "link",
+ regex: /^http.+/i,
+ fetch: function (url, done) {
+ done({
+ url: url,
+ type: "link",
+ token: "",
+ thumbnail: "",
+ title: "",
+ width: 100,
+ height: 100,
+ });
+ },
+ tag: function (media) {
+ return (
+ '<a href="' + media.url + '" target="_blank">' + media.url + "</a>"
+ );
+ },
+ },
+ ],
- tumblr: function(url, cb){
- var domain = url.replace(/^https?:\/\//,"").split("/")[0]
+ tumblr: function (url, cb) {
+ var domain = url.replace(/^https?:\/\//, "").split("/")[0];
if (domain.indexOf(".") == -1) {
- domain += ".tumblr.com"
+ domain += ".tumblr.com";
}
$.ajax({
- type: 'GET',
+ type: "GET",
url: "http://" + domain + "/api/read",
dataType: "jsonp",
data: {
format: "json",
},
- success: function(data){
- var media_list = []
- var blog = data.tumblelog
-
- data.posts.forEach(parse)
- cb(media_list)
+ success: function (data) {
+ var media_list = [];
+ var blog = data.tumblelog;
- function parse(post){
- var media, caption, url
+ data.posts.forEach(parse);
+ cb(media_list);
+
+ function parse(post) {
+ var media, caption, url;
switch (post.type) {
- case 'photo':
- caption = stripHTML(post['photo-caption'])
+ case "photo":
+ caption = stripHTML(post["photo-caption"]);
if (post.photos.length) {
- post.photos.forEach(function(photo){
+ post.photos.forEach(function (photo) {
var media = {
- url: photo['photo-url-1280'],
+ url: photo["photo-url-1280"],
type: "image",
token: "",
- thumbnail: photo['photo-url-500'],
+ thumbnail: photo["photo-url-500"],
description: caption,
width: parseInt(photo.width),
height: parseInt(photo.height),
- }
- media_list.push(media)
- })
- }
- else {
+ };
+ media_list.push(media);
+ });
+ } else {
media = {
- url: post['photo-url-1280'],
+ url: post["photo-url-1280"],
type: "image",
token: "",
- thumbnail: post['photo-url-500'],
+ thumbnail: post["photo-url-500"],
description: caption,
width: parseInt(post.width),
height: parseInt(post.height),
- }
- media_list.push(media)
+ };
+ media_list.push(media);
+ }
+ break;
+ case "video":
+ url = post["video-source"];
+ if (url.indexOf("http") !== 0) {
+ break;
}
- break
- case 'video':
- url = post['video-source']
- if (url.indexOf("http") !== 0) { break }
if (Parser.lookup.youtube.regex.test(url)) {
- var id = (url.match(/v=([-_a-zA-Z0-9]{11})/i) || url.match(/youtu.be\/([-_a-zA-Z0-9]{11})/i) || url.match(/embed\/([-_a-zA-Z0-9]{11})/i))[1].split('&')[0];
- var thumb = "http://i.ytimg.com/vi/" + id + "/hqdefault.jpg"
+ var id = (url.match(/v=([-_a-zA-Z0-9]{11})/i) ||
+ url.match(/youtu.be\/([-_a-zA-Z0-9]{11})/i) ||
+ url.match(/embed\/([-_a-zA-Z0-9]{11})/i))[1].split("&")[0];
+ var thumb = "http://i.ytimg.com/vi/" + id + "/hqdefault.jpg";
media = {
- url: post['video-source'],
+ url: post["video-source"],
type: "youtube",
token: id,
thumbnail: thumb,
- title: stripHTML(post['video-caption']),
+ title: stripHTML(post["video-caption"]),
width: 640,
height: 360,
autoplay: false,
loop: false,
- }
- media_list.push(media)
+ };
+ media_list.push(media);
}
- break
+ break;
}
}
-// console.log(post)
+ // console.log(post)
+ },
+ });
+ },
+
+ parse: function (url, cb) {
+ var matched = Parser.integrations.some(function (integration) {
+ if (integration.regex.test(url)) {
+ integration.fetch(url, function (res) {
+ cb(res);
+ });
+ return true;
}
- })
+ return false;
+ });
+ if (!matched) {
+ cb(null);
+ }
},
- parse: function (url, cb) {
- var matched = Parser.integrations.some(function(integration){
- if (integration.regex.test(url)) {
- integration.fetch(url, function(res){
- cb(res)
- })
- return true
- }
- return false
- })
- if (! matched) {
- cb(null)
- }
- },
-
- tag: function (media){
- if (media.type in Parser.lookup) {
- return Parser.lookup[media.type].tag(media)
- }
- return ""
- },
+ tag: function (media) {
+ if (media.type in Parser.lookup) {
+ return Parser.lookup[media.type].tag(media);
+ }
+ return "";
+ },
+
+ loadImage: function (url, cb, error) {
+ if (Parser.lookup.image.regex.test(url)) {
+ Parser.lookup.image.fetch(url, function (media) {
+ cb(media);
+ });
+ } else error && error();
+ },
- loadImage: function(url, cb, error){
- if (Parser.lookup.image.regex.test(url)) {
- Parser.lookup.image.fetch(url, function(media){
- cb(media)
- })
- }
- else error && error()
- },
-
thumbnail: function (media) {
return '<img src="' + (media.thumbnail || media.url) + '" class="thumb">';
},
-
};
-Parser.lookup = _.indexBy(Parser.integrations, 'type');
+Parser.lookup = _.indexBy(Parser.integrations, "type");
diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js
index d300dac..40c6fa7 100644
--- a/themes/okadmin/public/js/upload.js
+++ b/themes/okadmin/public/js/upload.js
@@ -34,7 +34,7 @@ OKUpload.prototype.parse = function (url) {
if (!url) return;
var uploader = this;
Parser.parse(url, function (media) {
- console.log(url, media);
+ // console.log(url, media);
if (!media) {
alert("Not a valid link");
} else if (media.type == "image") {
@@ -88,6 +88,12 @@ OKUpload.prototype.upload = function (f) {
}
field = "audio";
action = this.audioAction;
+ } else if (f.type.match("application.*") || f.type.match("text.*")) {
+ if (this.config.fileMaxbytes && f.size > this.config.fileMaxbytes) {
+ return this.largeFileError(f, this.config.fileMaxbytes);
+ }
+ field = "file";
+ action = this.fileAction;
} else {
if (this.config.imageMaxbytes && f.size > this.config.imageMaxbytes) {
return this.largeFileError(f, this.config.imageMaxbytes);
@@ -136,7 +142,7 @@ OKUpload.prototype.upload = function (f) {
console.log("ERROR PARSING JSON");
}
}
- console.log(arguments, request);
+ // console.log(arguments, request);
}
function transferError(data) {
console.log("Transfer error");
@@ -148,7 +154,7 @@ OKUpload.prototype.upload = function (f) {
console.log("Transfer aborted");
this.loadCount += 1;
this.hideUploadBars();
- console.log(arguments);
+ // console.log(arguments);
}
request.send(fd);
diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid
index a7c3caa..15dae0f 100644
--- a/themes/okadmin/templates/partials/inputs.liquid
+++ b/themes/okadmin/templates/partials/inputs.liquid
@@ -65,7 +65,7 @@
</div>
{% elsif type == 'file' %}
- <div class="image group {% if spec.value.uri %}loaded{% endif %}">
+ <div class="file group {% if spec.value.uri %}loaded{% endif %}">
<div class="fields">
<div class="add-image-button">
<input type="file">