Skip to content

Commit 78cb554

Browse files
committed
New examples.
1 parent aae84b7 commit 78cb554

File tree

31 files changed

+302
-2
lines changed

31 files changed

+302
-2
lines changed

mixedreplace-both/1.jpg

2.36 KB
Loading

mixedreplace-both/2.jpg

3.39 KB
Loading

mixedreplace-both/3.jpg

4.07 KB
Loading

mixedreplace-both/4.jpg

3.23 KB
Loading

mixedreplace-both/5.jpg

3.24 KB
Loading
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
exports.install = function() {
2+
F.route('/');
3+
F.route('/live/', view_live);
4+
5+
// uploading
6+
F.mmr('/', upload);
7+
};
8+
9+
var files = [];
10+
11+
function upload(req, file, counter) {
12+
if (!file)
13+
return;
14+
console.log('UPLOAD', counter);
15+
if (files.length > 20)
16+
framework.unlink([files.shift()]);
17+
files.push(file.path);
18+
}
19+
20+
function view_live() {
21+
var self = this;
22+
self.interval = setInterval(function() {
23+
24+
if (!self.isConnected) {
25+
clearInterval(self.interval);
26+
return;
27+
}
28+
29+
var latest = files[files.length - 1];
30+
if (self.filename === latest)
31+
return;
32+
33+
self.filename = latest;
34+
self.mmr('live.jpg', latest);
35+
}, 500);
36+
}

mixedreplace-both/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ===================================================
2+
// IMPORTANT: only for development
3+
// total.js - web application framework for node.js
4+
// http://www.totaljs.com
5+
// ===================================================
6+
7+
require('total.js').http('debug');

mixedreplace-both/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This example works on in Total.js `v2.0.2`.
2+
3+
- you need to run `index.js` (Total.js app)
4+
- then you need to execu script `upload.js`

mixedreplace-both/upload.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
require('total.js');
2+
3+
const Url = require('url');
4+
const Http = require('http');
5+
const Path = require('path');
6+
const Fs = require('fs');
7+
8+
// directory must contain only files
9+
//var directory = process.;
10+
11+
var BOUNDARY = '----' + Math.random().toString(16).substring(2);
12+
var files = [];
13+
14+
function send(url) {
15+
16+
var indexer = 0;
17+
var counter = 0;
18+
var uri = Url.parse(url);
19+
var headers = { 'Content-Type': 'multipart/x-mixed-replace; boundary=' + BOUNDARY };
20+
var options = { protocol: uri.protocol, auth: uri.auth, method: 'POST', hostname: uri.hostname, port: uri.port, path: uri.path, agent: false, headers: headers };
21+
22+
var response = function(res) {
23+
res.on('end', () => console.log(res.statusCode));
24+
res.resume();
25+
};
26+
27+
var con = Http;
28+
var req = con.request(options, response);
29+
30+
req.on('error', (err) => console.log('ERROR', err, err.stack));
31+
32+
function sendfile(filename, cb) {
33+
var header = '\r\n\r\n--' + BOUNDARY + '\r\nContent-Disposition: form-data; name="File"; filename="' + Path.basename(filename) + '"\r\nContent-Type: ' + U.getContentType(U.getExtension(filename)) +'\r\n\r\n';
34+
req.write(header);
35+
var stream = Fs.createReadStream(filename);
36+
stream.pipe(req, { end: false });
37+
stream.on('end', cb);
38+
}
39+
40+
function run() {
41+
counter++;
42+
43+
if (counter > 50) {
44+
req.end('\r\n\r\n--' + BOUNDARY + '--');
45+
console.log('END');
46+
return;
47+
}
48+
49+
setTimeout(function() {
50+
var file = files[indexer++];
51+
52+
if (!file) {
53+
indexer = 0;
54+
file = files[indexer++];
55+
}
56+
57+
if (file.length) {
58+
console.log('–---->', file);
59+
sendfile(file, run);
60+
}
61+
}, 500);
62+
}
63+
64+
run();
65+
};
66+
67+
var directory = process.cwd();
68+
69+
Fs.readdirSync(directory).forEach(function(filename){
70+
if (filename.lastIndexOf('.jpg') !== -1)
71+
files.push(Path.join(directory, filename));
72+
});
73+
74+
send('http://127.0.0.1:8000/');

mixedreplace-both/views/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@{layout('')}
2+
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<title>Live Streaming</title>
7+
<meta charset="utf-8" />
8+
<meta http-equiv="X-UA-Compatible" content="IE=10" />
9+
<meta name="format-detection" content="telephone=no"/>
10+
</head>
11+
<body>
12+
13+
<img src="/live/" width="200" height="200" border="0" />
14+
15+
</body>
16+
</html>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
exports.install = function() {
2+
F.route('/');
3+
F.route('/live/', view_live);
4+
};
5+
6+
function view_live() {
7+
8+
var self = this;
9+
var index = 0;
10+
var count = 0;
11+
12+
// Sends 5 times 5 pictures
13+
var interval = setInterval(function() {
14+
15+
index++;
16+
17+
if (index > 5) {
18+
index = 1;
19+
count++;
20+
}
21+
22+
if (!self.isConnected) {
23+
clearInterval(interval);
24+
return;
25+
}
26+
27+
self.mmr(self.path.public('img/' + index + '.jpg'));
28+
// self.mmr(filename or name when the stream exists, [stream], [callback])
29+
30+
if (count > 5) {
31+
clearInterval(interval);
32+
self.close();
33+
}
34+
35+
}, 500);
36+
}

mixedreplace-download/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ===================================================
2+
// IMPORTANT: only for development
3+
// total.js - web application framework for node.js
4+
// http://www.totaljs.com
5+
// ===================================================
6+
7+
require('total.js').http('debug');
2.36 KB
Loading
3.39 KB
Loading
4.07 KB
Loading
3.23 KB
Loading
3.24 KB
Loading

mixedreplace-download/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This example works on in Total.js `v2.0.2`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@{layout('')}
2+
3+
<!DOCTYPE html>
4+
<html>
5+
<head>
6+
<title>Live Streaming</title>
7+
<meta charset="utf-8" />
8+
<meta http-equiv="X-UA-Compatible" content="IE=10" />
9+
<meta name="format-detection" content="telephone=no"/>
10+
</head>
11+
<body>
12+
13+
<img src="/live/" width="200" height="200" border="0" />
14+
15+
</body>
16+
</html>

mixedreplace-upload/1.jpg

2.36 KB
Loading

mixedreplace-upload/2.jpg

3.39 KB
Loading

mixedreplace-upload/3.jpg

4.07 KB
Loading

mixedreplace-upload/4.jpg

3.23 KB
Loading

mixedreplace-upload/5.jpg

3.24 KB
Loading
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
exports.install = function() {
2+
F.mmr('/', upload);
3+
};
4+
5+
var files = [];
6+
7+
function upload(req, file, counter) {
8+
9+
if (file === null) {
10+
framework.unlink(files);
11+
return;
12+
}
13+
14+
console.log('--->', counter, file.filename);
15+
files.push(file.path);
16+
}

mixedreplace-upload/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ===================================================
2+
// IMPORTANT: only for development
3+
// total.js - web application framework for node.js
4+
// http://www.totaljs.com
5+
// ===================================================
6+
7+
require('total.js').http('debug');

mixedreplace-upload/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This example works on in Total.js `v2.0.2`.
2+
3+
- you need to run `index.js` (Total.js app)
4+
- then you need to execu script `upload.js`

mixedreplace-upload/upload.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
require('total.js');
2+
3+
const Url = require('url');
4+
const Http = require('http');
5+
const Path = require('path');
6+
const Fs = require('fs');
7+
8+
// directory must contain only files
9+
//var directory = process.;
10+
11+
var BOUNDARY = '----' + Math.random().toString(16).substring(2);
12+
var files = [];
13+
14+
function send(url) {
15+
16+
var indexer = 0;
17+
var uri = Url.parse(url);
18+
var headers = { 'Content-Type': 'multipart/x-mixed-replace; boundary=' + BOUNDARY };
19+
var options = { protocol: uri.protocol, auth: uri.auth, method: 'POST', hostname: uri.hostname, port: uri.port, path: uri.path, agent: false, headers: headers };
20+
21+
var response = function(res) {
22+
res.on('end', () => console.log(res.statusCode));
23+
res.resume();
24+
};
25+
26+
var con = Http;
27+
var req = con.request(options, response);
28+
29+
req.on('error', (err) => console.log('ERROR', err, err.stack));
30+
31+
function sendfile(filename, cb) {
32+
var header = '\r\n\r\n--' + BOUNDARY + '\r\nContent-Disposition: form-data; name="File"; filename="' + Path.basename(filename) + '"\r\nContent-Type: ' + U.getContentType(U.getExtension(filename)) +'\r\n\r\n';
33+
req.write(header);
34+
var stream = Fs.createReadStream(filename);
35+
stream.pipe(req, { end: false });
36+
stream.on('end', cb);
37+
}
38+
39+
function run() {
40+
indexer++;
41+
42+
if (indexer > 5) {
43+
req.end('\r\n\r\n--' + BOUNDARY + '--');
44+
console.log('END');
45+
return;
46+
}
47+
48+
setTimeout(function() {
49+
var file = files.shift() || '';
50+
if (file.length) {
51+
console.log('–---->', file);
52+
sendfile(file, run);
53+
}
54+
}, 500);
55+
}
56+
57+
run();
58+
};
59+
60+
var directory = process.cwd();
61+
62+
Fs.readdirSync(directory).forEach(function(filename){
63+
if (filename.lastIndexOf('.jpg') !== -1)
64+
files.push(Path.join(directory, filename));
65+
});
66+
67+
send('http://127.0.0.1:8000/');

routing-resize/definitions/resize.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ F.resize('/img/50percent/', function(image) {
2323

2424
F.resize('/img/medium/', function(image) {
2525
image.resize('70%');
26-
}, ['/img/', '.png']);
26+
}, ['/img/', '.png']);
27+
28+
F.resize('/img/blur/', function(image) {
29+
image.resize(100, 100);
30+
image.quality(90);
31+
image.blur(1);
32+
image.minify();
33+
}, ['~' + F.path.root()]);
34+
35+
console.log(F.path.root());

routing-resize/header.jpg

68.2 KB
Loading

static-version/versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/css/style.css : /css/style001.css
99

1010
// The framework creates mapping
11-
/img/logo.png --> /img/logo003.png
11+
/img/logo.png --> /img/logo004.png
1212

1313
// The framework prepares CSS background(url()):
1414
/img/bg.png : /img/bg002.png

0 commit comments

Comments
 (0)