Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
ipfs-images-components
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ipfs-images
ipfs-images-components
Commits
77ac847f
Commit
77ac847f
authored
Aug 27, 2018
by
Дмитрий Никулин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not try to clean objects that are missing from IPFS
parent
827f2dc4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
19 deletions
+27
-19
cleaner.js
components/cleaner.js
+24
-19
ipfs.js
components/storage-backends/ipfs.js
+3
-0
No files found.
components/cleaner.js
View file @
77ac847f
...
@@ -85,30 +85,35 @@ class Cleaner {
...
@@ -85,30 +85,35 @@ class Cleaner {
run
()
{
run
()
{
let
timestamp
=
Date
.
now
()
-
this
.
expire
*
1000
;
let
timestamp
=
Date
.
now
()
-
this
.
expire
*
1000
;
let
date
=
new
Date
(
timestamp
).
toUTCString
();
let
date
=
new
Date
(
timestamp
).
toUTCString
();
const
ipfs
=
new
Ipfs
();
logging
.
info
(
`Performing cleanup of attachments uploaded earlier
logging
.
info
(
`Performing cleanup of attachments uploaded earlier
than '
${
date
}
'`
);
than '
${
date
}
'`
);
return
redis
.
zrangebyscoreAsync
(
this
.
index
,
[
logging
.
info
(
`Loading list of local attachments (ipfs pin ls). Please be patient, this can take a lot of time`
);
'-inf'
,
timestamp
,
]).
then
((
list
)
=>
{
return
ipfs
.
getLocalObjects
().
then
(
hashes
=>
{
if
(
list
.
length
<=
0
)
{
const
hashSet
=
new
Set
(
hashes
);
logging
.
info
(
'Nothing to clean'
);
logging
.
info
(
'Looking for outdated attachments...'
);
return
Promise
.
resolve
(
list
.
length
);
return
redis
.
zrangebyscoreAsync
(
this
.
index
,
[
}
'-inf'
,
timestamp
,
]).
then
(
list
=>
{
logging
.
info
(
`Deleting
${
list
.
length
}
attachments`
);
list
=
list
.
filter
(
hash
=>
hashSet
.
has
(
hash
));
if
(
list
.
length
<=
0
)
{
let
ipfs
=
new
Ipfs
();
logging
.
info
(
'Nothing to clean'
);
let
metadata
=
new
Metadata
();
return
Promise
.
resolve
(
list
.
length
);
}
return
Promise
.
mapSeries
(
list
,
(
hash
)
=>
this
.
delAttachment
(
hash
)
logging
.
info
(
`Deleting
${
list
.
length
}
attachments`
);
).
then
(()
=>
{
logging
.
info
(
`Successfully deleted
${
list
.
length
}
attachments`
);
return
Promise
.
map
(
list
,
(
hash
)
=>
{
return
this
.
delAttachment
(
hash
);
}).
then
(()
=>
{
logging
.
info
(
`Successfully deleted
${
list
.
length
}
attachments`
);
});
}).
catch
((
error
)
=>
{
logging
.
error
(
error
);
});
});
}).
catch
((
error
)
=>
{
logging
.
error
(
error
);
});
});
}
}
}
}
...
...
components/storage-backends/ipfs.js
View file @
77ac847f
...
@@ -68,6 +68,9 @@ class IpfsStorage {
...
@@ -68,6 +68,9 @@ class IpfsStorage {
});
});
}
}
getLocalObjects
()
{
return
this
.
ipfs
.
pin
.
ls
();
}
/**
/**
* Pins a file by hash.
* Pins a file by hash.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment