forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate untranslated files (freeCodeCamp#44462)
- Loading branch information
Nicholas Carrigan (he/him)
authored
Dec 10, 2021
1 parent
f8eec5d
commit 010e09f
Showing
18 changed files
with
1,694 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...t-and-apis/back-end-development-and-apis-projects/file-metadata-microservice.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
id: bd7158d8c443edefaeb5bd0f | ||
title: File Metadata Microservice | ||
challengeType: 4 | ||
forumTopicId: 301506 | ||
dashedName: file-metadata-microservice | ||
--- | ||
|
||
# --description-- | ||
|
||
Build a full stack JavaScript app that is functionally similar to this: <https://file-metadata-microservice.freecodecamp.rocks/>. Working on this project will involve you writing your code using one of the following methods: | ||
|
||
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-filemetadata/) and complete your project locally. | ||
- Use [our Replit starter project](https://replit.com/github/freeCodeCamp/boilerplate-project-filemetadata) to complete your project. | ||
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo. | ||
|
||
When you are done, make sure a working demo of your project is hosted somewhere public. Then submit the URL to it in the `Solution Link` field. Optionally, also submit a link to your project's source code in the `GitHub Link` field. | ||
|
||
# --instructions-- | ||
|
||
**HINT:** You can use the `multer` npm package to handle file uploading. | ||
|
||
# --hints-- | ||
|
||
You should provide your own project, not the example URL. | ||
|
||
```js | ||
(getUserInput) => { | ||
assert( | ||
!/.*\/file-metadata-microservice\.freecodecamp\.rocks/.test( | ||
getUserInput('url') | ||
) | ||
); | ||
}; | ||
``` | ||
|
||
You can submit a form that includes a file upload. | ||
|
||
```js | ||
async (getUserInput) => { | ||
const site = await fetch(getUserInput('url')); | ||
const data = await site.text(); | ||
const doc = new DOMParser().parseFromString(data, 'text/html'); | ||
assert(doc.querySelector('input[type="file"]')); | ||
}; | ||
``` | ||
|
||
The form file input field has the `name` attribute set to `upfile`. | ||
|
||
```js | ||
async (getUserInput) => { | ||
const site = await fetch(getUserInput('url')); | ||
const data = await site.text(); | ||
const doc = new DOMParser().parseFromString(data, 'text/html'); | ||
assert(doc.querySelector('input[name="upfile"]')); | ||
}; | ||
``` | ||
|
||
When you submit a file, you receive the file `name`, `type`, and `size` in bytes within the JSON response. | ||
|
||
```js | ||
async (getUserInput) => { | ||
const formData = new FormData(); | ||
const fileData = await fetch( | ||
'https://cdn.freecodecamp.org/weather-icons/01d.png' | ||
); | ||
const file = await fileData.blob(); | ||
formData.append('upfile', file, 'icon'); | ||
const data = await fetch(getUserInput('url') + '/api/fileanalyse', { | ||
method: 'POST', | ||
body: formData | ||
}); | ||
const parsed = await data.json(); | ||
assert.property(parsed, 'size'); | ||
assert.equal(parsed.name, 'icon'); | ||
assert.equal(parsed.type, 'image/png'); | ||
}; | ||
``` | ||
|
||
# --solutions-- | ||
|
||
```js | ||
/** | ||
Backend challenges don't need solutions, | ||
because they would need to be tested against a full working project. | ||
Please check our contributing guidelines to learn more. | ||
*/ | ||
``` |
156 changes: 156 additions & 0 deletions
156
...pment-and-apis/back-end-development-and-apis-projects/timestamp-microservice.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
--- | ||
id: bd7158d8c443edefaeb5bdef | ||
title: Timestamp Microservice | ||
challengeType: 4 | ||
forumTopicId: 301508 | ||
dashedName: timestamp-microservice | ||
--- | ||
|
||
# --description-- | ||
|
||
Build a full stack JavaScript app that is functionally similar to this: <https://timestamp-microservice.freecodecamp.rocks/>. Working on this project will involve you writing your code using one of the following methods: | ||
|
||
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-timestamp/) and complete your project locally. | ||
- Use [our Replit starter project](https://replit.com/github/freeCodeCamp/boilerplate-project-timestamp) to complete your project. | ||
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo. | ||
|
||
When you are done, make sure a working demo of your project is hosted somewhere public. Then submit the URL to it in the `Solution Link` field. Optionally, also submit a link to your project's source code in the `GitHub Link` field. | ||
|
||
**Note:** Time zones conversion is not a purpose of this project, so assume all sent valid dates will be parsed with `new Date()` as GMT dates. | ||
|
||
# --hints-- | ||
|
||
You should provide your own project, not the example URL. | ||
|
||
```js | ||
(getUserInput) => { | ||
assert( | ||
!/.*\/timestamp-microservice\.freecodecamp\.rocks/.test(getUserInput('url')) | ||
); | ||
}; | ||
``` | ||
|
||
A request to `/api/:date?` with a valid date should return a JSON object with a `unix` key that is a Unix timestamp of the input date in milliseconds | ||
|
||
```js | ||
(getUserInput) => | ||
$.get(getUserInput('url') + '/api/2016-12-25').then( | ||
(data) => { | ||
assert.equal( | ||
data.unix, | ||
1482624000000, | ||
'Should be a valid unix timestamp' | ||
); | ||
}, | ||
(xhr) => { | ||
throw new Error(xhr.responseText); | ||
} | ||
); | ||
``` | ||
|
||
A request to `/api/:date?` with a valid date should return a JSON object with a `utc` key that is a string of the input date in the format: `Thu, 01 Jan 1970 00:00:00 GMT` | ||
|
||
```js | ||
(getUserInput) => | ||
$.get(getUserInput('url') + '/api/2016-12-25').then( | ||
(data) => { | ||
assert.equal( | ||
data.utc, | ||
'Sun, 25 Dec 2016 00:00:00 GMT', | ||
'Should be a valid UTC date string' | ||
); | ||
}, | ||
(xhr) => { | ||
throw new Error(xhr.responseText); | ||
} | ||
); | ||
``` | ||
|
||
A request to `/api/1451001600000` should return `{ unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }` | ||
|
||
```js | ||
(getUserInput) => | ||
$.get(getUserInput('url') + '/api/1451001600000').then( | ||
(data) => { | ||
assert( | ||
data.unix === 1451001600000 && | ||
data.utc === 'Fri, 25 Dec 2015 00:00:00 GMT' | ||
); | ||
}, | ||
(xhr) => { | ||
throw new Error(xhr.responseText); | ||
} | ||
); | ||
``` | ||
|
||
Your project can handle dates that can be successfully parsed by `new Date(date_string)` | ||
|
||
```js | ||
(getUserInput) => | ||
$.get(getUserInput('url') + '/api/05 October 2011, GMT').then( | ||
(data) => { | ||
assert( | ||
data.unix === 1317772800000 && | ||
data.utc === 'Wed, 05 Oct 2011 00:00:00 GMT' | ||
); | ||
}, | ||
(xhr) => { | ||
throw new Error(xhr.responseText); | ||
} | ||
); | ||
``` | ||
|
||
If the input date string is invalid, the api returns an object having the structure `{ error : "Invalid Date" }` | ||
|
||
```js | ||
(getUserInput) => | ||
$.get(getUserInput('url') + '/api/this-is-not-a-date').then( | ||
(data) => { | ||
assert.equal(data.error.toLowerCase(), 'invalid date'); | ||
}, | ||
(xhr) => { | ||
assert(xhr.responseJSON.error.toLowerCase() === 'invalid date'); | ||
} | ||
); | ||
``` | ||
|
||
An empty date parameter should return the current time in a JSON object with a `unix` key | ||
|
||
```js | ||
(getUserInput) => | ||
$.get(getUserInput('url') + '/api').then( | ||
(data) => { | ||
var now = Date.now(); | ||
assert.approximately(data.unix, now, 20000); | ||
}, | ||
(xhr) => { | ||
throw new Error(xhr.responseText); | ||
} | ||
); | ||
``` | ||
|
||
An empty date parameter should return the current time in a JSON object with a `utc` key | ||
|
||
```js | ||
(getUserInput) => | ||
$.get(getUserInput('url') + '/api').then( | ||
(data) => { | ||
var now = Date.now(); | ||
var serverTime = new Date(data.utc).getTime(); | ||
assert.approximately(serverTime, now, 20000); | ||
}, | ||
(xhr) => { | ||
throw new Error(xhr.responseText); | ||
} | ||
); | ||
``` | ||
|
||
# --solutions-- | ||
|
||
```js | ||
/** | ||
Backend challenges don't need solutions, | ||
because they would need to be tested against a full working project. | ||
Please check our contributing guidelines to learn more. | ||
*/ | ||
``` |
119 changes: 119 additions & 0 deletions
119
...t-and-apis/back-end-development-and-apis-projects/url-shortener-microservice.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
--- | ||
id: bd7158d8c443edefaeb5bd0e | ||
title: URL Shortener Microservice | ||
challengeType: 4 | ||
forumTopicId: 301509 | ||
dashedName: url-shortener-microservice | ||
--- | ||
|
||
# --description-- | ||
|
||
Build a full stack JavaScript app that is functionally similar to this: <https://url-shortener-microservice.freecodecamp.rocks/>. Working on this project will involve you writing your code using one of the following methods: | ||
|
||
- Clone [this GitHub repo](https://github.com/freeCodeCamp/boilerplate-project-urlshortener/) and complete your project locally. | ||
- Use [our Replit starter project](https://replit.com/github/freeCodeCamp/boilerplate-project-urlshortener) to complete your project. | ||
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo. | ||
|
||
When you are done, make sure a working demo of your project is hosted somewhere public. Then submit the URL to it in the `Solution Link` field. Optionally, also submit a link to your project's source code in the `GitHub Link` field. | ||
|
||
# --instructions-- | ||
|
||
**HINT:** Do not forget to use a body parsing middleware to handle the POST requests. Also, you can use the function `dns.lookup(host, cb)` from the `dns` core module to verify a submitted URL. | ||
|
||
# --hints-- | ||
|
||
You should provide your own project, not the example URL. | ||
|
||
```js | ||
(getUserInput) => { | ||
assert( | ||
!/.*\/url-shortener-microservice\.freecodecamp\.rocks/.test( | ||
getUserInput('url') | ||
) | ||
); | ||
}; | ||
``` | ||
|
||
You can POST a URL to `/api/shorturl` and get a JSON response with `original_url` and `short_url` properties. Here's an example: `{ original_url : 'https://freeCodeCamp.org', short_url : 1}` | ||
|
||
```js | ||
async (getUserInput) => { | ||
const url = getUserInput('url'); | ||
const urlVariable = Date.now(); | ||
const fullUrl = `${url}/?v=${urlVariable}` | ||
const res = await fetch(url + '/api/shorturl', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
body: `url=${fullUrl}` | ||
}); | ||
if (res.ok) { | ||
const { short_url, original_url } = await res.json(); | ||
assert.isNotNull(short_url); | ||
assert.strictEqual(original_url, `${url}/?v=${urlVariable}`); | ||
} else { | ||
throw new Error(`${res.status} ${res.statusText}`); | ||
} | ||
}; | ||
``` | ||
|
||
When you visit `/api/shorturl/<short_url>`, you will be redirected to the original URL. | ||
|
||
```js | ||
async (getUserInput) => { | ||
const url = getUserInput('url'); | ||
const urlVariable = Date.now(); | ||
const fullUrl = `${url}/?v=${urlVariable}` | ||
let shortenedUrlVariable; | ||
const postResponse = await fetch(url + '/api/shorturl', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
body: `url=${fullUrl}` | ||
}); | ||
if (postResponse.ok) { | ||
const { short_url } = await postResponse.json(); | ||
shortenedUrlVariable = short_url; | ||
} else { | ||
throw new Error(`${postResponse.status} ${postResponse.statusText}`); | ||
} | ||
const getResponse = await fetch( | ||
url + '/api/shorturl/' + shortenedUrlVariable | ||
); | ||
if (getResponse) { | ||
const { redirected, url } = getResponse; | ||
assert.isTrue(redirected); | ||
assert.strictEqual(url,fullUrl); | ||
} else { | ||
throw new Error(`${getResponse.status} ${getResponse.statusText}`); | ||
} | ||
}; | ||
``` | ||
|
||
If you pass an invalid URL that doesn't follow the valid `http://www.example.com` format, the JSON response will contain `{ error: 'invalid url' }` | ||
|
||
```js | ||
async (getUserInput) => { | ||
const url = getUserInput('url'); | ||
const res = await fetch(url + '/api/shorturl', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
body: `url=ftp:/john-doe.org` | ||
}); | ||
if (res.ok) { | ||
const { error } = await res.json(); | ||
assert.isNotNull(error); | ||
assert.strictEqual(error.toLowerCase(), 'invalid url'); | ||
} else { | ||
throw new Error(`${res.status} ${res.statusText}`); | ||
} | ||
}; | ||
``` | ||
|
||
# --solutions-- | ||
|
||
```js | ||
/** | ||
Backend challenges don't need solutions, | ||
because they would need to be tested against a full working project. | ||
Please check our contributing guidelines to learn more. | ||
*/ | ||
``` |
Oops, something went wrong.