Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WiPho
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan Grewe
WiPho
Commits
f8b2457f
Commit
f8b2457f
authored
10 years ago
by
Jan Grewe
Browse files
Options
Downloads
Patches
Plain Diff
try to download missing photos after receiving the first one and when reconnecting
parent
d016fea8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.js
+82
-9
82 additions, 9 deletions
app.js
routes/index.js
+1
-1
1 addition, 1 deletion
routes/index.js
with
83 additions
and
10 deletions
app.js
+
82
−
9
View file @
f8b2457f
...
@@ -5,12 +5,17 @@ var pathPhotos = config.pathPhotos;
...
@@ -5,12 +5,17 @@ var pathPhotos = config.pathPhotos;
var
previewWidth
=
config
.
previewWidth
;
var
previewWidth
=
config
.
previewWidth
;
var
previewHeight
=
config
.
previewHeight
;
var
previewHeight
=
config
.
previewHeight
;
var
cardAddr
=
config
.
broadcastAddr
;
var
cardAddr
=
config
.
broadcastAddr
;
var
pathPreviews
=
"
./public/previews
"
;
var
cardPath
=
null
;
var
pathPreviews
=
'
./public/previews
'
;
var
itvPing
=
null
;
var
itvPing
=
null
;
var
cardFound
=
false
;
var
cardFound
=
false
;
var
alreadySearching
=
false
;
var
alreadySearching
=
false
;
var
alreadyDownloading
=
false
;
var
downloadPrevious
=
true
;
var
downloadList
=
new
Array
();
var
os
=
require
(
'
os
'
);
var
http
=
require
(
'
http
'
);
var
http
=
require
(
'
http
'
);
var
path
=
require
(
'
path
'
);
var
path
=
require
(
'
path
'
);
var
net
=
require
(
'
net
'
);
var
net
=
require
(
'
net
'
);
...
@@ -39,7 +44,7 @@ app.set('view engine', 'jade');
...
@@ -39,7 +44,7 @@ app.set('view engine', 'jade');
// uncomment after placing your favicon in /public
// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
//app.use(favicon(__dirname + '/public/favicon.ico'));
app
.
use
(
logger
(
'
dev
'
));
//
app.use(logger('dev'));
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
cookieParser
());
app
.
use
(
cookieParser
());
...
@@ -93,13 +98,16 @@ console.log("#########################################");
...
@@ -93,13 +98,16 @@ console.log("#########################################");
findCard
();
findCard
();
function
downloadPhoto
(
path
)
{
function
downloadPhoto
s
()
{
path
=
path
.
substr
(
5
).
replace
(
/
\0
/g
,
''
);
if
(
alreadyDownloading
==
true
||
downloadList
.
length
<
1
)
var
photo
=
path
.
split
(
'
/
'
).
pop
();
return
true
;
alreadyDownloading
=
true
;
var
photo
=
downloadList
.
pop
();
var
localFile
=
pathPhotos
+
'
/
'
+
photo
;
var
localFile
=
pathPhotos
+
'
/
'
+
photo
;
var
localPreview
=
pathPreviews
+
'
/
'
+
photo
;
var
localPreview
=
pathPreviews
+
'
/
'
+
photo
;
console
.
log
(
'
[
'
+
photo
+
'
] Downloading from http://
'
+
cardAddr
+
path
);
console
.
log
(
'
[
'
+
photo
+
'
] Downloading from http://
'
+
cardAddr
+
cardPath
+
'
/
'
+
photo
);
var
file
=
fs
.
createWriteStream
(
localFile
);
var
file
=
fs
.
createWriteStream
(
localFile
);
...
@@ -109,6 +117,7 @@ function downloadPhoto(path) {
...
@@ -109,6 +117,7 @@ function downloadPhoto(path) {
file
.
on
(
'
finish
'
,
function
()
{
file
.
on
(
'
finish
'
,
function
()
{
file
.
close
();
file
.
close
();
alreadyDownloading
=
false
;
console
.
log
(
'
[
'
+
photo
+
'
] Saved as
'
+
localFile
);
console
.
log
(
'
[
'
+
photo
+
'
] Saved as
'
+
localFile
);
gm
(
localFile
).
autoOrient
().
resize
(
previewWidth
,
previewHeight
).
write
(
localPreview
,
function
(
err
)
{
gm
(
localFile
).
autoOrient
().
resize
(
previewWidth
,
previewHeight
).
write
(
localPreview
,
function
(
err
)
{
...
@@ -125,12 +134,22 @@ function downloadPhoto(path) {
...
@@ -125,12 +134,22 @@ function downloadPhoto(path) {
});
});
if
(
downloadPrevious
==
true
)
{
getPhotoList
();
}
if
(
downloadList
.
length
>
0
)
{
downloadPhotos
();
}
else
{
console
.
log
(
"
All photos downloaded, waiting for new ones...
"
);
}
});
});
var
options
=
{
var
options
=
{
hostname
:
cardAddr
,
hostname
:
cardAddr
,
port
:
80
,
port
:
80
,
path
:
path
,
path
:
cardPath
+
'
/
'
+
photo
,
method
:
'
GET
'
method
:
'
GET
'
};
};
...
@@ -144,6 +163,52 @@ function downloadPhoto(path) {
...
@@ -144,6 +163,52 @@ function downloadPhoto(path) {
}
}
function
getPhotoList
()
{
downloadPrevious
=
false
;
var
options
=
{
host
:
cardAddr
,
port
:
80
,
path
:
'
/cgi-bin/tslist?PATH=/www
'
+
cardPath
+
'
&keepfresh=
'
+
Date
.
now
().
toString
()
};
http
.
get
(
options
,
function
(
resp
){
console
.
log
(
"
Getting list of photos on card...
"
);
resp
.
on
(
'
data
'
,
function
(
data
){
var
strFiles
=
data
.
toString
().
split
(
os
.
EOL
)[
2
];
var
regex
=
/FileName
\d
+=
([
a-zA-Z0-9_
\.]
+
)
&FileType
\d
+=File&/g
;
var
arrPhotos
=
new
Array
();
while
(
match
=
regex
.
exec
(
strFiles
))
{
arrPhotos
.
push
(
match
[
1
]);
}
var
i
=
0
;
arrPhotos
.
forEach
(
function
(
photo
)
{
fs
.
exists
(
pathPhotos
+
'
/
'
+
photo
,
function
(
exists
)
{
if
(
exists
)
{
//console.log('['+photo+'] Photo '+photo+' already downloaded!');
}
else
{
console
.
log
(
'
[
'
+
photo
+
'
] Photo
'
+
photo
+
'
not downloaded yet, adding to download list!
'
);
downloadList
.
push
(
photo
);
}
i
++
;
if
(
i
==
arrPhotos
.
length
-
1
)
{
if
(
downloadList
.
length
>
0
)
{
downloadPhotos
();
}
else
{
console
.
log
(
"
All photos already downloaded!
"
);
}
}
});
});
});
}).
on
(
"
error
"
,
function
(
e
){
console
.
log
(
"
Error getting photo list:
"
+
e
.
message
);
getPhotoList
();
});
}
function
enableShootAndView
(
ip
)
{
function
enableShootAndView
(
ip
)
{
...
@@ -153,6 +218,9 @@ function enableShootAndView(ip) {
...
@@ -153,6 +218,9 @@ function enableShootAndView(ip) {
client
.
on
(
'
connect
'
,
function
()
{
client
.
on
(
'
connect
'
,
function
()
{
console
.
log
(
'
Shoot & View enabled, waiting for photos...
'
);
console
.
log
(
'
Shoot & View enabled, waiting for photos...
'
);
if
(
cardPath
!=
null
)
{
getPhotoList
();
}
});
});
client
.
on
(
'
error
'
,
function
(
err
)
{
client
.
on
(
'
error
'
,
function
(
err
)
{
...
@@ -161,7 +229,11 @@ function enableShootAndView(ip) {
...
@@ -161,7 +229,11 @@ function enableShootAndView(ip) {
});
});
client
.
on
(
'
data
'
,
function
(
data
)
{
client
.
on
(
'
data
'
,
function
(
data
)
{
downloadPhoto
(
data
.
toString
());
var
path
=
data
.
toString
().
substr
(
5
).
replace
(
/
\0
/g
,
''
);
var
photo
=
path
.
split
(
'
/
'
).
pop
();
cardPath
=
path
.
substring
(
0
,
path
.
lastIndexOf
(
'
/
'
));
downloadList
.
push
(
photo
);
downloadPhotos
();
});
});
client
.
on
(
'
end
'
,
function
()
{
client
.
on
(
'
end
'
,
function
()
{
...
@@ -188,6 +260,7 @@ function pingCard(ip) {
...
@@ -188,6 +260,7 @@ function pingCard(ip) {
req
.
setTimeout
(
5000
,
function
()
{
req
.
setTimeout
(
5000
,
function
()
{
cardFound
=
false
;
cardFound
=
false
;
downloadPrevious
=
true
;
console
.
log
(
'
Card has disappeared!
'
);
console
.
log
(
'
Card has disappeared!
'
);
req
.
destroy
();
req
.
destroy
();
clearInterval
(
itvPing
);
clearInterval
(
itvPing
);
...
@@ -239,7 +312,7 @@ function findCard() {
...
@@ -239,7 +312,7 @@ function findCard() {
sendSearch
();
sendSearch
();
itvSearch
=
setInterval
(
function
()
{
itvSearch
=
setInterval
(
function
()
{
sendSearch
();
sendSearch
();
},
5
000
);
},
2
000
);
function
sendSearch
()
{
function
sendSearch
()
{
socket
.
send
(
message
,
0
,
message
.
length
,
55777
,
cardAddr
,
function
(
err
,
bytes
)
{
socket
.
send
(
message
,
0
,
message
.
length
,
55777
,
cardAddr
,
function
(
err
,
bytes
)
{
...
...
This diff is collapsed.
Click to expand it.
routes/index.js
+
1
−
1
View file @
f8b2457f
...
@@ -3,7 +3,7 @@ var router = express.Router();
...
@@ -3,7 +3,7 @@ var router = express.Router();
/* GET home page. */
/* GET home page. */
router
.
get
(
'
/
'
,
function
(
req
,
res
)
{
router
.
get
(
'
/
'
,
function
(
req
,
res
)
{
res
.
render
(
'
index
'
,
{
title
:
'
Express
'
});
res
.
render
(
'
index
'
,
{
title
:
'
WiPho
'
});
});
});
module
.
exports
=
router
;
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment