textiot
Version:
A framework for building web and native (IoT) Dapps on the IPFS network
85 lines (84 loc) • 3.23 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const api_1 = require("../core/api");
const config_1 = __importDefault(require("./config"));
const files_1 = __importDefault(require("./files"));
/**
* Profile is an API module for accessing public profile information
*/
class Profile extends api_1.API {
constructor(opts = api_1.DEFAULT_API_OPTIONS) {
super(opts);
this.config = new config_1.default(opts);
this.files = new files_1.default(opts);
}
/**
* Retrieve the local node's public profile peer information
* @returns The local node's peer information
*/
get() {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendGet('profile');
return response.json();
});
}
/**
* Get the local node's public profile display name
* @returns Node's public profile display name
*/
name() {
return __awaiter(this, void 0, void 0, function* () {
const contact = yield this.get();
return contact.name;
});
}
/**
* Set the local node's public profile display name
*
* @param name Username string
* @returns Whether the update was successful
*/
setName(name) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield this.sendPost('profile/name', [name]);
return response.status === 201;
});
}
/**
* Get the local node's public profile avatar image hash
* @returns Node's public profile avatar image hash
*/
avatar() {
return __awaiter(this, void 0, void 0, function* () {
const contact = yield this.get();
return contact.avatar;
});
}
/**
* Set the local node's public profile avatar image
*
* @param image Image to use as new avatar. Can be any input type accepted by [[Files.add]].
* @returns Whether the update was successful
*/
setAvatar(image) {
return __awaiter(this, void 0, void 0, function* () {
const thread = yield this.config.get('Account.Thread');
yield this.files.add(image, 'avatar', thread);
const response = yield this.sendPost('profile/avatar');
return response.status === 201;
});
}
}
exports.default = Profile;
;