FILE_REFERENCE_EXPIRED at upload.getFile with inputPhotoFileLocation - download

Can't get content from method upload.getFile using inputPhotoFileLocation, getting exeption FILE_REFERENCE_EXPIRED, readed lots of forums but cant get answer
I'm using MTProto client on js
this.call('upload.getFile', {
location: {
_: 'inputPhotoFileLocation',
id: message.media.photo.id,
access_hash: message.media.photo.access_hash,
file_reference: message.media.photo.file_reference, //tried
//Buffer.from(message.media.photo.file_reference.toString('hex'), 'hex'),
//[...message.media.photo.file_reference] and others
thumb_size: JSON.stringify(message.media.photo.sizes.find(size => size._ == 'photoSizeProgressive'))
},
offset: 0,
limit: 1024 * 1024
})

https://core.telegram.org/constructor/inputPhotoFileLocation
You must pass type from message.media.photo.sizes in the thumb_size field
That is, instead of JSON.stringify(message.media.photo.sizes.find(size => size._ == 'photoSizeProgressive')) you need to specify message.media.photo.sizes.find(size => size._ == 'photoSizeProgressive').type

Related

Remove particular type of error from Datadog

Currently, I see error status for all the authentication errors and it feels like a lot of extra noise in the total errors chart. I looked at https://github.com/DataDog/dd-trace-js/pull/909 and tried to use the custom execute provided for graphql
import ddTrace from 'dd-trace'
let tracer = ddTrace.init({
debug: false
}) // initialized in a different file to avoid hoisting.
tracer.use('graphql', {
hooks: {
execute: (span, args, res) => {
if (res && res.errors && res.errors[0] && res.errors[0].status !== 403) {
span?.setTag('error', res.errors)
}
}
}
})
export default tracer
But still, res with only 403 error is going into error status. Please help me with how can I achieve this.
Update: I found this bit of code in the tracing client repo:
tracer.use('graphql', {
hooks: {
execute: (span, args, res) => {
if (res?.errors?.[0]?.status === 403) { // assuming "status" is a number
span?.setTag('error', null) // remove any error set by the tracer
}
}
}
})
https://github.com/DataDog/dd-trace-js/issues/1249
maybe it would help
Old message:
Never mind. seems like my solution is only for express, graphql doesn't support that property
You probably want to just modify the validateStatus property in the http module:
Callback function to determine if there was an error. It should take a status code as its only parameter and return true for success or false for errors
https://datadoghq.dev/dd-trace-js/interfaces/plugins.http.html#validatestatus
As an example you should be able to mark 403s as not be errors with something like this:
const tracer = require('dd-trace').init();
tracer.use('express', {
validateStatus: code => code < 400 && code != 403
})

Cypress: cy.window(): Unable to get property values

Goal
Hello, I wish to gather custom property values for a window object of a page using cy.window().
Issue
When using cy.log() jointly with JSON.stringify(), it presents that it does have properties with values; however, when using lodash _.has(), does not have these properties and thereby no value because these properties are not found.
Code
The following Cypress custom command using cy.window() gathers custom window's property
export function cmdCypressWindow($propName: string) {
cy.window()
.its($propName)
.then(($propValue: Cypress.AUTWindow) => {
cy.log('props names:', JSON.stringify(Object.getOwnPropertyNames($propValue), null, 2));
cy.log('props values:', JSON.stringify($propValue, null, 2));
cy.log('VERSION prop:', _.has($propValue, 'VERSION'));
cy.log('HOST prop:', _.has($propValue, 'HOST'));
cy.log('VERSION value:', _.get($propValue, 'VERSION'));
cy.log('HOST value:', _.get($propValue, 'HOST'));
});
}
Passed in for parameter $propName value 'ACT', because I am expecting the page's window object to contain window.ACT["VERSION"].
Using the example code, the log output shows that the page's window does contain property ACT["VERSION"].
However, when accessing this window object, listed properties are unavailable and undefined:
window
- its .ACT
log props names:, [ "__esModule", "VERSION", "HOST", "RulesList", "RulesAddEdit", "AppsList", "AppsOAuth", "AppsAdd" ]
log props values:, { "VERSION": "0.2.11", "HOST": "radmin" }
log VERSION prop:, false
log HOST prop:, false
log VERSION value:
log HOST value:
How do I resolve this? Thank you, all feedback is very much appreciated.
Found part of the solution here:
TypeScript: Find Key / Value in Object (list comprehension?)
Modified the function:
export function cmdCypressWindow($propName: string) {
cy.window()
.its($propName)
.then(($propValue: Cypress.AUTWindow) => {
const actValues: Record<string, string> = {};
Object.keys($propValue).forEach(key => {
// #ts-ignore
if (typeof $propValue[key] !== 'function') {
// #ts-ignore
actValues[key as string] = $propValue[key];
}
});
cy.log(`window.${$propName}`, JSON.stringify(actValues, null, 2));
cy.wrap(actValues);
});
}
Results show that I was able to acquire values from window object:
log props names:, [ "__esModule", "VERSION", "HOST", "RulesList", "RulesAddEdit", "AppsList", "AppsOAuth", "AppsAdd" ]
log window.ACT, { "VERSION": "0.2.11", "HOST": "radmin" }
wrap {version: 0.2.11, host: radmin}

Cypress - extract URL info

I have this URL :
https://www.acme.com/book/passengers?id=h1c7cafc-5457-4564-af9d-2599c6a37dde&hash=7EPbMqFFQu8T5R3AQr1GCw&gtmsearchtype=City+Break
and want to store these values :
id=h1c7cafc-5457-4564-af9d-2599c6a37dde
hash=7EPbMqFFQu8T5R3AQr1GCw
for use in a later test.
How do I extract these values from the URL? I am using Cypress. Thanks.
Please follow the following steps and that's all there is to it.
You can put this snippet into before() hooks of your spec file and you can access them wherever you want.
cy.location().then(fullUrl => {
let pathName = fullUrl.pathname
let arr = pathName.split('?');
let arrayValues = arr[1].split('&');
cy.log(arrayValues[0]);
cy.log(arrayValues[1]);
cy.log(arrayValues[2]);
})
In case anyone needs the correct answer, use the cy.location('search') to extract the search part of the location data.
Then for convenience, convert it to a javascript object with key/value pairs for each item.
Finally, store it in a Cypress alias to use later in the test.
cy.location('search')
.then(search=> {
const searchValues = search.split('?')[1].split('&')
// yields: [
// id=h1c7cafc-5457-4564-af9d-2599c6a37dde,
// hash=7EPbMqFFQu8T5R3AQr1GCw,
// gtmsearchtype=City+Break
// ]
const searchMap = searchValues.reduce((acc,item) => {
const [key,value] = item.split('=')
acc[key] = value.replace('+', ' ')
return acc
}, {})
// yields: {
// id: "h1c7cafc-5457-4564-af9d-2599c6a37dde",
// hash: "7EPbMqFFQu8T5R3AQr1GCw",
// gtmsearchtype: "City Break"
// }
cy.wrap(searchMap).as('searchMap')
})
Using #Srinu Kodi's answer I got it working changing ...then(fullUrl => ... to
...then((fullUrl) => ...

Posting object to Google Cloud Storage doesn't replace ${filename} variable

As described here https://cloud.google.com/storage/docs/xml-api/post-object
I can use ${filename} as part of the key when uploading a file to GCS from the browser (using a signed request).
That's great, because it's the exact same variable S3 uses. But - a problem. It doesn't actually replace ${filename} with the name of the file when I upload. This works perfectly on S3, but with GCS I literally get $%7Bfilename%7D as the key in the response - clearly it's not replacing this with the correct value.
I'm building the request like so:
export function uploadVideo(video) {
return new Promise((resolve, reject) => {
if (!video) {
resolve(null);
return;
}
// this fetches a presigned post object from the server:
request.get('/presigned_post')
.query({format: 'json'})
.end((err, response)=> {
if (!err && response.ok) {
request
.post(`https://${response.body.url.host}/`)
.field(response.body.fields)
.field('Content-Type', image.type)
.attach('file', image, image.name)
.end((err, response) => {
if (err) {
console.log("Error uploading image: ", err);
reject(err);
} else {
resolve({
location: response.text.match('<Location>' + '(.*?)' + '</Location>')[1],
bucket: response.text.match('<Bucket>' + '(.*?)' + '</Bucket>')[1],
key: response.text.match('<Key>' + '(.*?)' + '</Key>')[1],
checksum: response.text.match('<ETag>"' + '(.*?)' + '"</ETag>')[1]
});
}
});
}
});
});
}
The key is some_folder/${filename} and this is included in the form data to google (in response.fields).
You can see I am providing the filename with .attach('file', image, image.name). It is uploading correctly, just not replacing the ${filename} var.
edit
I have narrowed down the issue more. We query S3 and GCS to get the fields in the presigned post. With S3, if I give a key of ${filename} then I get exactly that returned in the fields:
def presigned_post(bucket_name:, key:, **opts)
response = s3_resource.
bucket(bucket_name).
presigned_post(key: key, content_type_starts_with: '', **opts)
{
fields: response.fields,
url: { host: URI.parse(response.url).host }
}
end
Fields here will contain "key"=>"${filename}".
However in the GCS case, the following code returns :key=>"$%7Bfilename%7D" in the fields:
# https://cloud.google.com/storage/docs/xml-api/post-object#usage_and_examples
# https://www.rubydoc.info/gems/google-cloud-storage/1.0.1/Google/Cloud/Storage/Bucket:post_object
def presigned_post(bucket_name:, key:, acl:, success_action_status:, expiration: nil)
expiration ||= (Time.now + 1.hour).iso8601
policy = {
expiration: expiration,
conditions: [
["starts-with", "$key", "" ],
["starts-with", "$Content-Type", "" ],
{ acl: acl },
{ success_action_status: success_action_status }
]
}
post_obj = get_bucket!(bucket_name).post_object(key, policy: policy)
url_obj = { host: URI.parse(post_obj.url).host }
# Have to manually merge in these fields
fields = post_obj.fields.merge(
acl: acl,
success_action_status: success_action_status
)
return { fields: fields, url: url_obj }
end
If i manually change the key in the GCS request fields, then it works. Is that really what I'm supposed to do?
A fix for this issue was released in google-cloud-storage v1.24.0.
Figured out the issue is caused by:
def ext_path
URI.escape "/#{#bucket}/#{#path}"
end
in lib/google/cloud/storage/file.rb of the google-cloud-ruby-gem.
This is called by def post_object in that same file.
I am going to raise an issue on their Github page.

Property doesn't exist on type {}

I am trying to get a list of objects from a firebase db using snapshotChanges.
Angular Version: 7.2.0,
Firebase Version: 5.8.1,
RxJS Version: 6.3.3,
AngularFire2: 5.1.1
My code is the following:
this.fbSubs.push(this.db
.collection('availableExercises')
.snapshotChanges()
.pipe(
map(docArray => {
return docArray.map(doc => {
return {
idExercise: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories
};
});
})
)
.subscribe((exercises: Exercise[]) => {
// code...
}, error => {
// code...
}));
When I try to compile this code, I get the following errors:
ERROR in src/app/training/training.service.ts(41,44): error TS2339: Property 'name' does not exist on type '{}'.
src/app/training/training.service.ts(42,48): error TS2339: Property 'duration' does not exist on type '{}'.
src/app/training/training.service.ts(43,48): error TS2339: Property 'calories' does not exist on type '{}'.
I believe the syntax may be outdated from a previous version of RxJS but I can't seem to work out what I need to change.
So I had to slightly change the code around in .pipe.map() to return the data as "Exercise" like so:
.pipe(
map(docArray => {
return docArray.map(doc => {
const data = doc.payload.doc.data() as Exercise;
const idExercise = doc.payload.doc.id;
return {idExercise, ...data};
});
})
)
.pipe(
map(docArray => {
return docArray.map(doc => {
return {
id: doc.payload.doc.id,
...doc.payload.doc.data() as Exercise
};
});
})
)

Resources