forked from Flowee/registry
Also extract images / icons from nfts
This commit is contained in:
+38
-4
@@ -19,6 +19,17 @@ static QString pathWithSlash(const QString &input) {
|
|||||||
return input + '/';
|
return input + '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool walk(QJsonObject &item, const QStringList &steps) {
|
||||||
|
for (const auto &step : steps) {
|
||||||
|
auto x = item[step];
|
||||||
|
if (!x.isObject())
|
||||||
|
return false;
|
||||||
|
item = x.toObject();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Processor::Processor(const QString &inDir, const QString &outDir)
|
Processor::Processor(const QString &inDir, const QString &outDir)
|
||||||
: m_inDir(inDir),
|
: m_inDir(inDir),
|
||||||
m_outDir(pathWithSlash(outDir))
|
m_outDir(pathWithSlash(outDir))
|
||||||
@@ -54,7 +65,10 @@ bool Processor::run()
|
|||||||
QString path = m_outDir + source->hash + "/" + url.host() + url.path();
|
QString path = m_outDir + source->hash + "/" + url.host() + url.path();
|
||||||
if (QFile::exists(path))
|
if (QFile::exists(path))
|
||||||
continue;
|
continue;
|
||||||
|
if (url.scheme() == "ipfs") {
|
||||||
|
// use the main gateway for download
|
||||||
|
url = QUrl(QString("https://ipfs.io/ipfs/%1").arg(resource.mid(7)));
|
||||||
|
}
|
||||||
if (url.scheme() == "http" || url.scheme() == "https") {
|
if (url.scheme() == "http" || url.scheme() == "https") {
|
||||||
// schedule for download.
|
// schedule for download.
|
||||||
DownloadJob *job = new DownloadJob(&m_network);
|
DownloadJob *job = new DownloadJob(&m_network);
|
||||||
@@ -151,10 +165,12 @@ void Processor::parseBCMR(const QString &path)
|
|||||||
isTx = isTx && true;
|
isTx = isTx && true;
|
||||||
isJson = 10;
|
isJson = 10;
|
||||||
}
|
}
|
||||||
if (isJson <= 1 && (k == ' ' || k == '\n' || k == '\r' || k == '\t'))
|
if (k == ' ' || k == '\n' || k == '\r' || k == '\t') {
|
||||||
|
if (isJson < 1)
|
||||||
isJson = 1;
|
isJson = 1;
|
||||||
else if (isJson < 2 && k == '{')
|
} else if (isJson < 2 && k == '{') {
|
||||||
isJson = 2;
|
isJson = 2;
|
||||||
|
}
|
||||||
else if (isJson == 2 && (k < 34 || k > 'z')) {
|
else if (isJson == 2 && (k < 34 || k > 'z')) {
|
||||||
isJson = 10; // fail
|
isJson = 10; // fail
|
||||||
}
|
}
|
||||||
@@ -208,7 +224,7 @@ void Processor::parseBCMR(const QString &path)
|
|||||||
|
|
||||||
m_sources.push_back(me);
|
m_sources.push_back(me);
|
||||||
}
|
}
|
||||||
logInfo() << "Found BCMR for" << me->name;
|
logInfo() << "Found BCMR" << me->name << identity.key();
|
||||||
const auto uris_ = revision["uris"];
|
const auto uris_ = revision["uris"];
|
||||||
if (uris_.isObject()) {
|
if (uris_.isObject()) {
|
||||||
const auto uris = uris_.toObject();
|
const auto uris = uris_.toObject();
|
||||||
@@ -227,6 +243,24 @@ void Processor::parseBCMR(const QString &path)
|
|||||||
MetaCategory *mc = fetchOrCreate(cat);
|
MetaCategory *mc = fetchOrCreate(cat);
|
||||||
me->tokens.push_back(mc);
|
me->tokens.push_back(mc);
|
||||||
mc->owners.insert(me);
|
mc->owners.insert(me);
|
||||||
|
// walk all nfts and extract image and icon resource urls
|
||||||
|
auto types = token;
|
||||||
|
if (!walk(types, QStringList() << "nfts" << "parse" << "types"))
|
||||||
|
continue;
|
||||||
|
for (auto iter = types.begin(); iter != types.end(); ++iter) {
|
||||||
|
if (!iter->isObject())
|
||||||
|
continue;
|
||||||
|
auto uris = iter->toObject();
|
||||||
|
if (!walk(uris, QStringList() << "uris"))
|
||||||
|
continue;
|
||||||
|
auto image = uris["image"];
|
||||||
|
if (image.isString())
|
||||||
|
me->resources.insert(image.toString());
|
||||||
|
auto icon = uris["icon"];
|
||||||
|
if (icon.isString())
|
||||||
|
me->resources.insert(icon.toString());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user